Part Number Hot Search : 
D2508 C2000 MK5025 ATM10 A58005 G12232 FS020551 MC148906
Product Description
Full Text Search
 

To Download C167CS-LM Datasheet File

  If you can't view the Datasheet, Please click here to try to view without PDF Reader .  
 
 


  Datasheet File OCR Text:
  never stop thinking. microcontrollers users manual, v2.0, july 2000 c167cs derivatives 16-bit single-chip microcontroller
edition 2000-07 published by infineon technologies ag, st.-martin-strasse 53, d-81541 mnchen, germany ? infineon technologies ag 2000. all rights reserved. attention please! the information herein is given to describe certain components and shall not be considered as warranted characteristics. terms of delivery and rights to technical change reserved. we hereby disclaim any and all warranties, including but not limited to warranties of non-infringement, regarding circuits, descriptions and charts stated herein. infineon technologies is an approved cecc manufacturer. information for further information on technology, delivery terms and conditions and prices please contact your nearest infineon technologies office in germany or our infineon technologies representatives worldwide (see address list). warnings due to technical requirements components may contain dangerous substances. for information on the types in question please contact your nearest infineon technologies office. infineon technologies components may only be used in life-support devices or systems with the express written approval of infineon technologies, if a failure of such components can reasonably be expected to cause the failure of that life-support device or system, or to affect the safety or effectiveness of that device or system. life support devices or systems are intended to be implanted in the human body, or to support and/or maintain and sustain and/or protect human life. if they fail, it is reasonable to assume that the health of the user or other persons may be endangered.
microcontrollers users manual, v2.0, july 2000 never stop thinking. c167cs derivatives 16-bit single-chip microcontroller
c167cs revision history: v2.0, 2000-07 previous version: version 1.0, 1999-05 page subjects (major changes since last revision) all converted to new company layout all figures have been redrawn xxx flash descriptions removed 1-1 list of derivatives corrected 4-2 sleep mode added 6-7 description of pll base frequency improved 7-2 bit p4lin added 7-8 description of temperature compensation removed 7-14 description of port0 control corrected 7-17 f capcom2 output functionality added 7-20 figure corrected 7-37 open drain functionality described 7-54 note corrected 9-6 note reworked 9-28 note corrected 9-31 f description of bus arbitration improved 9-38 table reworked 9-39 f additional information 10-6 , 10-27 table enhanced 10-30 description of t5m corrected 11-13 f tables enhanced 12-5 description of transmission timing improved 12-13 baudrate tables improved 13-5 time range table improved 13-6 reset source table improved 15-2 f description of bsl entry improved 15-7 baudrate table added 16-7 frequency table enhanced 16-14 description improved (2 nd paragraph) 17-10 frequency and resolution table improved 18-1 p1dais corrected to p1didis 18-4 sample time control added 19-2 port 8 added
controller area network (can): license of robert bosch gmbh 19-12 bit timing section rearranged 20-13 figure corrected 20-18 software configuration introduced (see notes) 20-19 table enhanced for 33 mhz 20-22 code example corrected 20-23 address space for rstcon corrected 21-2 syscon1 added (3 rd paragraph) 21-15 flash control bits removed 21-21 frequency range table improved 21-22 ff description of security mechanism and sw examples reworked 22-5 linear stack size corrected 23-3 offset of rh7 corrected 23-4 ff c1lar, c2lar, rstcon added, ptcr, xadrs5 removed 25-2 figure corrected, pins 64 72 c167cs revision history: v2.0, 2000-07 (contd) previous version: version 1.0, 1999-05 page subjects (major changes since last revision) we listen to your comments any information within this document that you feel is wrong, unclear or missing at all? your feedback will help us to continuously improve the quality of this document. please send your proposal (including a reference to this document) to: mcdocu.comments@infineon.com
c167cs derivatives table of contents page users manual i-1 v2.0, 2000-07 1 introduction . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-1 1.1 the members of the 16-bit microcontroller family . . . . . . . . . . . . . . . . . 1-2 1.2 summary of basic features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-4 1.3 abbreviations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 1-7 2 architectural overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-1 2.1 basic cpu concepts and optimizations . . . . . . . . . . . . . . . . . . . . . . . . . 2-2 2.1.1 high instruction bandwidth/fast execution . . . . . . . . . . . . . . . . . . . . . 2-3 2.1.2 programmable multiple priority interrupt system . . . . . . . . . . . . . . . . 2-7 2.2 the on-chip system resources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-8 2.3 the on-chip peripheral blocks . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-11 2.4 power management features . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-18 2.5 protected bits . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 2-19 3 memory organization . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-1 3.1 internal rom area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-3 3.2 internal ram and sfr area . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-4 3.3 the on-chip xram . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-9 3.4 external memory space . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-11 3.5 crossing memory boundaries . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3-12 3.6 protection of the on-chip mask rom . . . . . . . . . . . . . . . . . . . . . . . . . . 3-13 4 the central processing unit (cpu) . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-1 4.1 instruction pipelining . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-3 4.2 particular pipeline effects . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-6 4.3 bit-handling and bit-protection . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-10 4.4 instruction state times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-11 4.5 cpu special function registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 4-12 5 interrupt and trap functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-1 5.1 interrupt system structure . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-2 5.1.1 interrupt control registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-6 5.2 operation of the pec channels . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-12 5.3 prioritization of interrupt and pec service requests . . . . . . . . . . . . . . 5-16 5.4 saving the status during interrupt service . . . . . . . . . . . . . . . . . . . . . . 5-18 5.5 interrupt response times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-20 5.6 pec response times . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-23 5.7 interrupt node sharing . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-25 5.8 external interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-26 5.9 trap functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 5-31 6 clock generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-1 6.1 oscillator . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-2 6.2 frequency control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-4
c167cs derivatives table of contents page users manual i-2 v2.0, 2000-07 6.3 oscillator watchdog . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-8 6.4 clock drivers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 6-9 7 parallel ports . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-1 7.1 input threshold control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-2 7.2 output driver control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-4 7.3 alternate port functions . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-9 7.4 port0 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-12 7.5 port1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-16 7.6 port 2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-23 7.7 port 3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-28 7.8 port 4 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-33 7.9 port 5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-38 7.10 port 6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-42 7.11 port 7 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-48 7.12 port 8 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 7-53 8 dedicated pins . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 8-1 9 the external bus interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-1 9.1 single chip mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-2 9.2 external bus modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-3 9.3 programmable bus characteristics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-12 9.4 ready controlled bus cycles . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-18 9.5 controlling the external bus controller . . . . . . . . . . . . . . . . . . . . . . . . . 9-20 9.6 ebc idle state . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-30 9.7 external bus arbitration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-31 9.8 the xbus interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 9-37 9.8.1 accessing the on-chip xbus peripherals . . . . . . . . . . . . . . . . . . . . . 9-38 9.8.2 external accesses to xbus peripherals . . . . . . . . . . . . . . . . . . . . . . 9-40 10 the general purpose timer units . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-1 10.1 timer block gpt1 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-1 10.1.1 gpt1 core timer t3 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-3 10.1.2 gpt1 auxiliary timers t2 and t4 . . . . . . . . . . . . . . . . . . . . . . . . . . 10-12 10.1.3 interrupt control for gpt1 timers . . . . . . . . . . . . . . . . . . . . . . . . . . 10-21 10.2 timer block gpt2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-22 10.2.1 gpt2 core timer t6 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-24 10.2.2 gpt2 auxiliary timer t5 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 10-30 10.2.3 interrupt control for gpt2 timers and caprel . . . . . . . . . . . . . . . 10-38 11 the asynchronous/synchronous serial interface . . . . . . . . . . . . . . 11-1 11.1 asynchronous operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-5 11.2 synchronous operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-8
c167cs derivatives table of contents page users manual i-3 v2.0, 2000-07 11.3 hardware error detection capabilities . . . . . . . . . . . . . . . . . . . . . . . . 11-10 11.4 asc0 baud rate generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-11 11.5 asc0 interrupt control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11-15 12 the high-speed synchronous serial interface . . . . . . . . . . . . . . . . . 12-1 12.1 full-duplex operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-7 12.2 half-duplex operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-10 12.3 continuous transfers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-11 12.4 port control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-12 12.5 baud rate generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-13 12.6 error detection mechanisms . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-15 12.7 ssc interrupt control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 12-17 13 the watchdog timer (wdt) . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-1 13.1 operation of the watchdog timer . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-3 13.2 reset source indication . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 13-6 14 the real time clock . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 14-1 15 the bootstrap loader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-1 15.1 entering the bootstrap loader . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-2 15.2 loading the startup code . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-5 15.3 exiting bootstrap loader mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-5 15.4 choosing the baudrate for the bsl . . . . . . . . . . . . . . . . . . . . . . . . . . . . 15-6 16 the capture/compare units . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-1 16.1 the capcom timers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-4 16.2 capcom unit timer interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-9 16.3 capture/compare registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-10 16.4 capture mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-13 16.5 compare modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-14 16.6 capture/compare interrupts . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 16-22 17 the pulse width modulation module . . . . . . . . . . . . . . . . . . . . . . . . . 17-1 17.1 operating modes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-2 17.2 pwm module registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-10 17.3 interrupt request generation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-14 17.4 pwm output signals . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 17-15 18 the analog/digital converter . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-1 18.1 mode selection and operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-3 18.2 conversion timing control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-13 18.3 a/d converter interrupt control . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 18-15 19 the on-chip can interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-1 19.1 functional blocks of the can module . . . . . . . . . . . . . . . . . . . . . . . . . . 19-3
c167cs derivatives table of contents page users manual i-4 v2.0, 2000-07 19.2 general functional description . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-8 19.2.1 can interrupt handling . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-10 19.2.2 configuration of the bit timing . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-12 19.2.3 mask registers . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-16 19.3 the message object . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-19 19.4 controlling the can module . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-31 19.5 configuration examples for message objects . . . . . . . . . . . . . . . . . . . 19-35 19.6 the second can module can2 . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-37 19.7 the can application interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 19-38 20 system reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-1 20.1 reset sources . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-2 20.2 status after reset . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-5 20.3 application-specific initialization routine . . . . . . . . . . . . . . . . . . . . . . . 20-9 20.4 system startup configuration . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-12 20.4.1 system startup configuration upon an external reset . . . . . . . . . . 20-13 20.4.2 system startup configuration upon a single-chip mode reset . . . 20-20 20.5 system configuration via software . . . . . . . . . . . . . . . . . . . . . . . . . . . 20-22 21 power management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-1 21.1 idle mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-3 21.2 sleep mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-5 21.3 power down mode . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-6 21.3.1 status of output pins during power reduction modes . . . . . . . . . . . 21-8 21.4 slow down operation . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-10 21.5 flexible peripheral management . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-14 21.6 programmable frequency output signal . . . . . . . . . . . . . . . . . . . . . . 21-17 21.7 security mechanism . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 21-22 22 system programming . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-1 22.1 stack operations . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-4 22.2 register banking . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-9 22.3 procedure call entry and exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-9 22.4 table searching . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-12 22.5 floating point support . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-12 22.6 peripheral control and interface . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-13 22.7 trap/interrupt entry and exit . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-13 22.8 unseparable instruction sequences . . . . . . . . . . . . . . . . . . . . . . . . . . 22-14 22.9 overriding the dpp addressing mechanism . . . . . . . . . . . . . . . . . . . . 22-14 22.10 handling the internal code memory . . . . . . . . . . . . . . . . . . . . . . . . . . 22-16 22.11 pits, traps and mines . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 22-18 23 the register set . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23-1 23.1 register description format . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23-1
c167cs derivatives table of contents page users manual i-5 v2.0, 2000-07 23.2 cpu general purpose registers (gprs) . . . . . . . . . . . . . . . . . . . . . . . 23-2 23.3 special function registers ordered by name . . . . . . . . . . . . . . . . . . . 23-4 23.4 special function registers ordered by address . . . . . . . . . . . . . . . . . 23-14 23.5 special notes . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 23-24 24 instruction set summary . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 24-1 25 device specification . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 25-1 26 keyword index . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 26-1
c167cs derivatives introduction users manual 1-1 v2.0, 2000-07 1 introduction the rapidly growing area of embedded control applications is representing one of the most time-critical operating environments for todays microcontrollers. complex control algorithms have to be processed based on a large number of digital as well as analog input signals, and the appropriate output signals must be generated within a defined maximum response time. embedded control applications also are often sensitive to board space, power consumption, and overall system cost. embedded control applications therefore require microcontrollers, which: ? offer a high level of system integration ? eliminate the need for additional peripheral devices and the associated software overhead ? provide system security and fail-safe mechanisms ? provide effective means to control (and reduce) the devices power consumption. with the increasing complexity of embedded control applications, a significant increase in cpu performance and peripheral functionality over conventional 8-bit controllers is required from microcontrollers for high-end embedded control systems. in order to achieve this high performance goal infineon has decided to develop its family of 16-bit cmos microcontrollers without the constraints of backward compatibility. of course the architecture of the 16-bit microcontroller family pursues successful hardware and software concepts, which have been established in infineons popular 8-bit controller families. about this manual this manual describes the functionality of a number of 16-bit microcontrollers of the infineon c166 family, the c167-class. as these microcontrollers provide a great extent of identical functionality it makes sense to describe a superset of the provided features. for this reason some sections of this manual do not refer to all the c167 derivatives that are offered (e.g. devices without on- chip program memory). these sections contain respective notes wherever possible. the descriptions in this manual refer to the following derivatives of the c167-class: ? c167cs-4rm version with 32 kbyte rom ? C167CS-LM version without on-chip program memory this manual is valid for the versions with on-chip rom of the mentioned derivatives as well as for the romless versions. of course it refers to all devices of the different available temperature ranges and packages. for simplicity all these various versions are referred to by the term c167cs throughout this manual. the complete pro-electron conforming designations are listed in the respective data sheets.
c167cs derivatives introduction users manual 1-2 v2.0, 2000-07 1.1 the members of the 16-bit microcontroller family the microcontrollers of the infineon 16-bit family have been designed to meet the high performance requirements of real-time embedded control applications. the architecture of this family has been optimized for high instruction throughput and minimum response time to external stimuli (interrupts). intelligent peripheral subsystems have been integrated to reduce the need for cpu intervention to a minimum extent. this also minimizes the need for communication via the external bus interface. the high flexibility of this architecture allows to serve the diverse and varying needs of different application areas such as automotive, industrial control, or data communications. the core of the 16-bit family has been developed with a modular family concept in mind. all family members execute an efficient control-optimized instruction set (additional instructions for members of the second generation). this allows an easy and quick implementation of new family members with different internal memory sizes and technologies, different sets of on-chip peripherals and/or different numbers of io pins. the xbus concept opens a straight forward path for the integration of application specific peripheral modules in addition to the standard on-chip peripherals in order to build application specific derivatives. as programs for embedded control applications become larger, high level languages are favored by programmers, because high level language programs are easier to write, to debug and to maintain. the 80c166-type microcontrollers were the first generation of the 16-bit controller family. these devices have established the c166 architecture. the c165-type and c167-type devices are members of the second generation of this family. this second generation is even more powerful due to additional instructions for hll support, an increased address space, increased internal ram and highly efficient management of various resources on the external bus. enhanced derivatives of this second generation provide additional features like additional internal high-speed ram, an integrated can-module, an on-chip pll, etc. utilizing integration to design efficient systems may require the integration of application specific peripherals to boost system performance, while minimizing the part count. these efforts are supported by the so-called xbus, defined for the infineon 16-bit microcontrollers (second generation). this xbus is an internal representation of the external bus interface that opens and simplifies the integration of peripherals by standardizing the required interface. one representative taking advantage of this technology is the integrated can module. the c165-type devices are reduced versions of the c167 which provide a smaller package and reduced power consumption at the expense of the a/d converter, the capcom units and the pwm module.
c167cs derivatives introduction users manual 1-3 v2.0, 2000-07 the c164-type devices and some of the c161-type devices are further enhanced by a flexible power management and form the third generation of the 16-bit controller family. this power management mechanism provides effective means to control the power that is consumed in a certain state of the controller and thus allows the minimization of the overall power consumption with respect to a given application. a variety of different versions is provided which offer various kinds of on-chip program memory: ? mask-programmable rom ? flash memory ? otp memory ? romless with no non-volatile memory at all. also there are devices with specific functional units. the devices may be offered in different packages, temperature ranges and speed classes. more standard and application-specific derivatives are planned and in development. note: not all derivatives will be offered in any temperature range, speed class, package or program memory variation. information about specific versions and derivatives will be made available with the devices themselves. contact your infineon representative for up-to-date material. note: as the architecture and the basic features (i.e. cpu core and built in peripherals) are identical for most of the currently offered versions of the c167cs, the descriptions within this manual that refer to the c167cs also apply to the other variations, unless otherwise noted.
c167cs derivatives introduction users manual 1-4 v2.0, 2000-07 1.2 summary of basic features the c167cs is an improved representative of the infineon family of full featured 16-bit single-chip cmos microcontrollers. it combines high cpu performance (up to 12.5/16.5 million instructions per second) with high peripheral functionality and means for power reduction. several key features contribute to the high performance of the c167cs (the indicated timings refer to a cpu clock of 25/33 mhz). high performance 16-bit cpu with four-stage pipeline ? 80/60 ns minimum instruction cycle time, with most instructions executed in 1 cycle ? 400/300 ns multiplication (16-bit 16-bit), 800/600 ns division (32-bit/16-bit) ? multiple high bandwidth internal data buses ? register based design with multiple variable register banks ? single cycle context switching support ? 16 mbytes linear address space for code and data (von neumann architecture) ? system stack cache support with automatic stack overflow/underflow detection control oriented instruction set with high efficiency ? bit, byte, and word data types ? flexible and efficient addressing modes for high code density ? enhanced boolean bit manipulation with direct addressability of 6 kbits for peripheral control and user defined flags ? hardware traps to identify exception conditions during runtime ? hll support for semaphore operations and efficient data access integrated on-chip memory ? 3 kbyte internal ram for variables, register banks, system stack and code ? 8 kbyte on-chip high-speed xram for variables, user stack and code ? 32 kbyte on-chip rom (not for romless devices) external bus interface ? multiplexed or demultiplexed bus configurations ? segmentation capability and chip select signal generation ? 8-bit or 16-bit data bus ? bus cycle characteristics selectable for five programmable address areas
c167cs derivatives introduction users manual 1-5 v2.0, 2000-07 16-priority-level interrupt system ? 56 interrupt nodes with separate interrupt vectors ? 240/180 ns typical interrupt latency (400/300 ns maximum) in case of internal program execution ? fast external interrupts 8-channel peripheral event controller (pec) ? interrupt driven single cycle data transfer ? transfer count option (std. cpu interrupt after programmable number of pec transfers) ? eliminates overhead of saving and restoring system state for interrupt requests intelligent on-chip peripheral subsystems ? 24-channel 10-bit a/d converter with programmable conversion time (7.76 m s minimum), auto scan modes, channel injection mode ? two 16-channel capture/compare units with 2 independent time bases each, very flexible pwm unit/event recording unit with different operating modes, includes four 16-bit timers/counters, maximum resolution f cpu /8 ? 4-channel pwm unit ? two multifunctional general purpose timer units gpt1: three 16-bit timers/counters, maximum resolution f cpu /8 gpt2: two 16-bit timers/counters, maximum resolution f cpu /4 ? asynchronous/synchronous serial channels (usart) with baud rate generator, parity, framing, and overrun error detection ? high speed synchronous serial channel programmable data length and shift direction ? two on-chip can bus modules, rev. 2.0b active ?real time clock ? watchdog timer with programmable time intervals ? bootstrap loader for flexible system initialization 111 io lines with individual bit addressability ? tri-stated in input mode ? selectable input thresholds (not on all pins) ? push/pull or open drain output mode ? programmable port driver control different temperature ranges ? 0 to + 70 c, C 40 to + 85 c, C 40 to + 125 c
c167cs derivatives introduction users manual 1-6 v2.0, 2000-07 infineon cmos process ? low power cmos technology including power saving idle and power down modes 144-pin plastic metric quad flat pack (mqfp) package ? p-mqfp, 28 28 mm body, 0.65 mm (25.6 mil) lead spacing, surface mount technology complete development support for the development tool support of its microcontrollers, infineon follows a clear third party concept. currently around 120 tool suppliers world-wide, ranging from local niche manufacturers to multinational companies with broad product portfolios, offer powerful development tools for the infineon c500 and c166 microcontroller families, guaranteeing a remarkable variety of price-performance classes as well as early availability of high quality key tools such as compilers, assemblers, simulators, debuggers or in-circuit emulators. infineon incorporates its strategic tool partners very early into the product development process, making sure embedded system developers get reliable, well-tuned tool solutions, which help them unleash the power of infineon microcontrollers in the most effective way and with the shortest possible learning curve. the tool environment for the infineon 16-bit microcontrollers includes the following tools: ? compilers (c, modula2, forth) ? macro-assemblers, linkers, locators, library managers, format-converters ? architectural simulators ? hll debuggers ? real-time operating systems ? vhdl chip models ? in-circuit emulators (based on bondout or standard chips) ? plug-in emulators ? emulation and clip-over adapters, production sockets ? logic analyzer disassemblers ? starter kits ? evaluation boards with monitor programs ? industrial boards (also for can, fuzzy, profibus, forth applications) ? network driver software (can, profibus)
c167cs derivatives introduction users manual 1-7 v2.0, 2000-07 1.3 abbreviations the following acronyms and terms are used within this document: adc analog digital converter ale address latch enable alu arithmetic and logic unit asc asynchronous/synchronous serial controller can controller area network (license bosch) capcom capture and compare unit cisc complex instruction set computing cmos complementary metal oxide silicon cpu central processing unit ebc external bus controller esfr extended special function register flash non-volatile memory that may be electrically erased gpr general purpose register gpt general purpose timer unit hll high level language io input/output otp one time programmable memory pec peripheral event controller pla programmable logic array pll phase locked loop pwm pulse width modulation ram random access memory risc reduced instruction set computing rom read only memory rtc real time clock sdd slow down divider sfr special function register ssc synchronous serial controller xbus internal representation of the external bus xram on-chip extension ram
c167cs derivatives architectural overview users manual 2-1 v2.0, 2000-07 2 architectural overview the architecture of the c167cs combines the advantages of both risc and cisc processors in a very well-balanced way. the sum of the features which are combined result in a high performance microcontroller, which is the right choice not only for todays applications, but also for future engineering challenges. the c167cs not only integrates a powerful cpu core and a set of peripheral units into one chip, but also connects the units in a very efficient way. one of the four buses used concurrently on the c167cs is the xbus, an internal representation of the external bus interface. this bus provides a standardized method of integrating application-specific peripherals to produce derivatives of the standard c167cs. figure 2-1 c167cs functional block diagram c166-core cpu port 2 interrupt bus xtal mcb04323_7csr osc / pll rtc wdt 32 16 interrupt controller 16-level priority pec external instr. / data gpt t2 t3 t4 t5 t6 ssc brgen (spi) asc0 brgen (usart) adc 10-bit 16+8 channels pwm ccom1 t0 t1 ccom2 t7 t8 ebc xbus control external bus control iram dual port internal ram 3 kbyte progmem rom 32 kbyte data data 16 16 16 can1 rev 2.0b active instr. / data port 0 xram 6+2 kbyte port 6 8 8 port 1 16 16 16 port 5 port 3 15 port 7 8 port 8 8 port 4 16 peripheral data bus 16 can2 rev 2.0b active on-chip xbus (16-bit demux)
c167cs derivatives architectural overview users manual 2-2 v2.0, 2000-07 2.1 basic cpu concepts and optimizations the main core of the cpu consists of a 4-stage instruction pipeline, a 16-bit arithmetic and logic unit (alu) and dedicated sfrs. additional hardware is provided for a separate multiply and divide unit, a bit-mask generator and a barrel shifter. figure 2-2 cpu block diagram to meet the demand for greater performance and flexibility, a number of areas has been optimized in the processor core. functional blocks in the cpu core are controlled by signals from the instruction decode logic. these are summarized below, and described in detail in the following sections: 1) high instruction bandwidth/fast execution 2) high function 8-bit and 16-bit arithmetic and logic unit 3) extended bit processing and peripheral control 4) high performance branch-, call-, and loop processing 5) consistent and optimized instruction formats 6) programmable multiple priority interrupt structure mcb02147 cpu sp stkov stkun instr. reg. instr. ptr. exec. unit 4-stage pipeline mdh mdl psw syscon context ptr. mul/div-hw r15 r0 general purpose registers bit-mask gen barrel - shifter alu (16-bit) data page ptr. code seg. ptr. internal ram r15 r0 rom 16 16 32 buscon 0 buscon 1 buscon 2 buscon 3 buscon 4 addrsel 4 addrsel 3 addrsel 2 addrsel 1
c167cs derivatives architectural overview users manual 2-3 v2.0, 2000-07 2.1.1 high instruction bandwidth/fast execution based on the hardware provisions, most of the c167css instructions can be executed in just one machine cycle, which requires 2 cpu clock cycles (2 1 / f cpu = 4 tcl). for example, shift and rotate instructions are always processed within one machine cycle, independent of the number of bits to be shifted. branch-, multiply- and divide instructions normally take more than one machine cycle. these instructions, however, have also been optimized. for example, branch instructions only require an additional machine cycle, when a branch is taken, and most branches taken in loops require no additional machine cycles at all, due to the so-called jump cache. a 32-bit/16-bit division takes 20 cpu clock cycles, a 16-bit 16-bit multiplication takes 10 cpu clock cycles. the instruction cycle time has been dramatically reduced through the use of instruction pipelining. this technique allows the core cpu to process portions of multiple sequential instruction stages in parallel. the following four stage pipeline provides the optimum balancing for the cpu core: fetch: in this stage, an instruction is fetched from the internal rom or ram or from the external memory, based on the current ip value. decode: in this stage, the previously fetched instruction is decoded and the required operands are fetched. execute: in this stage, the specified operation is performed on the previously fetched operands. write back: in this stage, the result is written to the specified location. if this technique were not used, each instruction would require four machine cycles. this increased performance allows a greater number of tasks and interrupts to be processed. instruction decoder instruction decoding is primarily generated from pla outputs based on the selected opcode. no microcode is used and each pipeline stage receives control signals staged in control registers from the decode stage plas. pipeline holds are primarily caused by wait states for external memory accesses and cause the holding of signals in the control registers. multiple-cycle instructions are performed through instruction injection and simple internal state machines which modify required control signals.
c167cs derivatives architectural overview users manual 2-4 v2.0, 2000-07 high function 8-bit and 16-bit arithmetic and logic unit all standard arithmetic and logical operations are performed in a 16-bit alu. in addition, for byte operations, signals are provided from bits six and seven of the alu result to correctly set the condition flags. multiple precision arithmetic is provided through a carry-in signal to the alu from previously calculated portions of the desired operation. most internal execution blocks have been optimized to perform operations on either 8-bit or 16-bit quantities. once the pipeline has been filled, one instruction is completed per machine cycle, except for multiply and divide. an advanced booth algorithm has been incorporated to allow four bits to be multiplied and two bits to be divided per machine cycle. thus, these operations use two coupled 16-bit registers, mdl and mdh, and require four and nine machine cycles, respectively, to perform a 16-bit by 16-bit (or 32-bit by 16-bit) calculation plus one machine cycle to setup and adjust the operands and the result. even these longer multiply and divide instructions can be interrupted during their execution to allow for very fast interrupt response. instructions have also been provided to allow byte packing in memory while providing sign extension of bytes for word wide arithmetic operations. the internal bus structure also allows transfers of bytes or words to or from peripherals based on the peripheral requirements. a set of consistent flags is automatically updated in the psw after each arithmetic, logical, shift, or movement operation. these flags allow branching on specific conditions. support for both signed and unsigned arithmetic is provided through user-specifiable branch tests. these flags are also preserved automatically by the cpu upon entry into an interrupt or trap routine. all targets for branch calculations are also computed in the central alu. a 16-bit barrel shifter provides multiple bit shifts in a single cycle. rotates and arithmetic shifts are also supported. extended bit processing and peripheral control a large number of instructions has been dedicated to bit processing. these instructions provide efficient control and testing of peripherals while enhancing data manipulation. unlike other microcontrollers, these instructions provide direct access to two operands in the bit-addressable space without requiring to move them into temporary flags. the same logical instructions available for words and bytes are also supported for bits. this allows the user to compare and modify a control bit for a peripheral in one instruction. multiple bit shift instructions have been included to avoid long instruction streams of single bit shift operations. these are also performed in a single machine cycle. in addition, bit field instructions have been provided, which allow the modification of multiple bits from one operand in a single instruction.
c167cs derivatives architectural overview users manual 2-5 v2.0, 2000-07 high performance branch-, call-, and loop processing due to the high percentage of branching in controller applications, branch instructions have been optimized to require one extra machine cycle only when a branch is taken. this is implemented by precalculating the target address while decoding the instruction. to decrease loop execution overhead, three enhancements have been provided: ? the first solution provides single cycle branch execution after the first iteration of a loop. thus, only one machine cycle is lost during the execution of the entire loop. in loops which fall through upon completion, no machine cycles are lost when exiting the loop. no special instructions are required to perform loops, and loops are automatically detected during execution of branch instructions. ? the second loop enhancement allows the detection of the end of a table and avoids the use of two compare instructions embedded in loops. one simply places the lowest negative number at the end of the specific table, and specifies branching if neither this value nor the compared value have been found. otherwise the loop is terminated if either condition has been met. the terminating condition can then be tested. ? the third loop enhancement provides a more flexible solution than the decrement and skip on zero instruction which is found in other microcontrollers. through the use of compare and increment or decrement instructions, the user can make comparisons to any value. this allows loop counters to cover any range. this is particularly advantageous in table searching. saving of system state is automatically performed on the internal system stack avoiding the use of instructions to preserve state upon entry and exit of interrupt or trap routines. call instructions push the value of the ip on the system stack, and require the same execution time as branch instructions. instructions have also been provided to support indirect branch and call instructions. this supports implementation of multiple case statement branching in assembler macros and high level languages.
c167cs derivatives architectural overview users manual 2-6 v2.0, 2000-07 consistent and optimized instruction formats to obtain optimum performance in a pipelined design, an instruction set has been designed which incorporates concepts from reduced instruction set computing (risc). these concepts primarily allow fast decoding of the instructions and operands while reducing pipeline holds. these concepts, however, do not preclude the use of complex instructions, which are required by microcontroller users. the following goals were used to design the instruction set: 1. provide powerful instructions to perform operations which currently require sequences of instructions and are frequently used. avoid transfer into and out of temporary registers such as accumulators and carry bits. perform tasks in parallel such as saving state upon entry into interrupt routines or subroutines. 2. avoid complex encoding schemes by placing operands in consistent fields for each instruction. also avoid complex addressing modes which are not frequently used. this decreases the instruction decode time while also simplifying the development of compilers and assemblers. 3. provide most frequently used instructions with one-word instruction formats. all other instructions are placed into two-word formats. this allows all instructions to be placed on word boundaries, which alleviates the need for complex alignment hardware. it also has the benefit of increasing the range for relative branching instructions. the high performance offered by the hardware implementation of the cpu can efficiently be utilized by a programmer via the highly functional c167cs instruction set which includes the following instruction classes: ? arithmetic instructions ? logical instructions ? boolean bit manipulation instructions ? compare and loop control instructions ? shift and rotate instructions ? prioritize instruction ? data movement instructions ? system stack instructions ? jump and call instructions ? return instructions ? system control instructions ? miscellaneous instructions possible operand types are bits, bytes and words. specific instruction support the conversion (extension) of bytes to words. a variety of direct, indirect or immediate addressing modes are provided to specify the required operands.
c167cs derivatives architectural overview users manual 2-7 v2.0, 2000-07 2.1.2 programmable multiple priority interrupt system the following enhancements have been included to allow processing of a large number of interrupt sources: 1. peripheral event controller (pec): this processor is used to off-load many interrupt requests from the cpu. it avoids the overhead of entering and exiting interrupt or trap routines by performing single-cycle interrupt-driven byte or word data transfers between any two locations in segment 0 with an optional increment of either the pec source or the destination pointer. just one cycle is stolen from the current cpu activity to perform a pec service. 2. multiple priority interrupt controller: this controller allows all interrupts to be placed at any specified priority. interrupts may also be grouped, which provides the user with the ability to prevent similar priority tasks from interrupting each other. for each of the possible interrupt sources there is a separate control register, which contains an interrupt request flag, an interrupt enable flag and an interrupt priority bitfield. once having been accepted by the cpu, an interrupt service can only be interrupted by a higher prioritized service request. for standard interrupt processing, each of the possible interrupt sources has a dedicated vector location. 3. multiple register banks: this feature allows the user to specify up to sixteen general purpose registers located anywhere in the internal ram. a single one-machine-cycle instruction allows to switch register banks from one task to another. 4. interruptable multiple cycle instructions: reduced interrupt latency is provided by allowing multiple-cycle instructions (multiply, divide) to be interruptable. with an interrupt response time within a range from just 5 to 10 cpu clock cycles (in case of internal program execution), the c167cs is capable of reacting very fast on non- deterministic events. its fast external interrupt inputs are sampled every cpu clock cycle and allow to recognize even very short external signals. the c167cs also provides an excellent mechanism to identify and to process exceptions or error conditions that arise during run-time, so called hardware traps. hardware traps cause an immediate non-maskable system reaction which is similar to a standard interrupt service (branching to a dedicated vector table location). the occurrence of a hardware trap is additionally signified by an individual bit in the trap flag register (tfr). except for another higher prioritized trap service being in progress, a hardware trap will interrupt any current program execution. in turn, hardware trap services can normally not be interrupted by standard or pec interrupts. software interrupts are supported by means of the trap instruction in combination with an individual trap (interrupt) number.
c167cs derivatives architectural overview users manual 2-8 v2.0, 2000-07 2.2 the on-chip system resources the c167cs controllers provide a number of powerful system resources designed around the cpu. the combination of cpu and these resources results in the high performance of the members of this controller family. peripheral event controller (pec) and interrupt control the peripheral event controller allows to respond to an interrupt request with a single data transfer (word or byte) which only consumes one instruction cycle and does not require to save and restore the machine status. each interrupt source is prioritized every machine cycle in the interrupt control block. if pec service is selected, a pec transfer is started. if cpu interrupt service is requested, the current cpu priority level stored in the psw register is tested to determine whether a higher priority interrupt is currently being serviced. when an interrupt is acknowledged, the current state of the machine is saved on the internal system stack and the cpu branches to the system specific vector for the peripheral. the pec contains a set of sfrs which store the count value and control bits for eight data transfer channels. in addition, the pec uses a dedicated area of ram which contains the source and destination addresses. the pec is controlled similar to any other peripheral through sfrs containing the desired configuration of each channel. an individual pec transfer counter is implicitly decremented for each pec service except forming in the continuous transfer mode. when this counter reaches zero, a standard interrupt is performed to the vector location related to the corresponding source. pec services are very well suited, for example, to move register contents to/ from a memory table. the c167cs has 8 pec channels each of which offers such fast interrupt-driven data transfer capabilities. memory areas the memory space of the c167cs is configured in a von neumann architecture which means that code memory, data memory, registers and io ports are organized within the same linear address space which covers up to 16 mbytes. the entire memory space can be accessed bytewise or wordwise. particular portions of the on-chip memory have additionally been made directly bit addressable. a 3 kbyte 16-bit wide internal ram (iram) provides fast access to general purpose registers (gprs), user data (variables) and system stack. the internal ram may also be used for code. a unique decoding scheme provides flexible user register banks in the internal memory while optimizing the remaining ram for user data.
c167cs derivatives architectural overview users manual 2-9 v2.0, 2000-07 the cpu has an actual register context consisting of up to 16 wordwide and/or bytewide gprs at its disposal, which are physically located within the on-chip ram area. a context pointer (cp) register determines the base address of the active register bank to be accessed by the cpu at a time. the number of register banks is only restricted by the available internal ram space. for easy parameter passing, a register bank may overlap others. a system stack of up to 1536 words is provided as a storage for temporary data. the system stack is also located within the on-chip ram area, and it is accessed by the cpu via the stack pointer (sp) register. two separate sfrs, stkov and stkun, are implicitly compared against the stack pointer value upon each stack access for the detection of a stack overflow or underflow. hardware detection of the selected memory space is placed at the internal memory decoders and allows the user to specify any address directly or indirectly and obtain the desired data without using temporary registers or special instructions. an 8 kbyte 16-bit wide on-chip xram (arranged in two blocks of 2 kbyte and 6 kbyte) provides fast access to user data (variables), user stacks and code. the on- chip xram is realized as an x-peripheral and appears to the software as an external ram. therefore it cannot store register banks and is not bitaddressable. the xram allows 16-bit accesses with maximum speed. for special function registers 1024 bytes of the address space are reserved. the standard special function register area (sfr) uses 512 bytes, while the extended special function register area (esfr) uses the other 512 bytes. (e)sfrs are wordwide registers which are used for controlling and monitoring functions of the different on-chip units. unused (e)sfr addresses are reserved for future members of the c166 family with enhanced functionality. an optional internal rom (32 kbyte) provides for both code and constant data storage. this memory area is connected to the cpu via a 32-bit-wide bus. thus, an entire double-word instruction can be fetched in just one machine cycle. program execution from on-chip program memory is the fastest of all possible alternatives.
c167cs derivatives architectural overview users manual 2-10 v2.0, 2000-07 external bus interface in order to meet the needs of designs where more memory is required than is provided on chip, up to 16 mbytes of external ram and/or rom can be connected to the microcontroller via its external bus interface. the integrated external bus controller (ebc) allows to access external memory and/or peripheral resources in a very flexible way. for up to five address areas the bus mode (multiplexed/demultiplexed), the data bus width (8-bit/16-bit) and even the length of a bus cycle (waitstates, signal delays) can be selected independently. this allows to access a variety of memory and peripheral components directly and with maximum efficiency. if the device does not run in single chip mode, where no external memory is required, the ebc can control external accesses in one of the following external access modes: ? 16-/18-/20-/24-bit addresses, 16-bit data, demultiplexed ? 16-/18-/20-/24-bit addresses, 8-bit data, demultiplexed ? 16-/18-/20-/24-bit addresses, 16-bit data, multiplexed ? 16-/18-/20-/24-bit addresses, 8-bit data, multiplexed the demultiplexed bus modes use port1 for addresses and port0 for data input/ output. the multiplexed bus modes use port0 for both addresses and data input/ output. port 4 is used for the upper address lines (a16 ) if selected. important timing characteristics of the external bus interface (waitstates, ale length and read/write delay) have been made programmable to allow the user the adaption of a wide range of different types of memories and/or peripherals. access to very slow memories or peripherals is supported via a particular ready function. for applications which require less than 64 kbytes of address space, a non-segmented memory model can be selected, where all locations can be addressed by 16-bits, and thus port 4 is not needed as an output for the upper address bits (axx a16), as is the case when using the segmented memory model. the on-chip xbus is an internal representation of the external bus and allows to access integrated application-specific peripherals/modules in the same way as external components. it provides a defined interface for these customized peripherals. the on-chip xram and the on-chip can-modules are examples for these x-peripherals.
c167cs derivatives architectural overview users manual 2-11 v2.0, 2000-07 2.3 the on-chip peripheral blocks the c166 family clearly separates peripherals from the core. this structure permits the maximum number of operations to be performed in parallel and allows peripherals to be added or deleted from family members without modifications to the core. each functional block processes data independently and communicates information over common buses. peripherals are controlled by data written to the respective special function registers (sfrs). these sfrs are located either within the standard sfr area (00fe00 h 00ffff h ) or within the extended esfr area (00f000 h 00f1ff h ). these built in peripherals either allow the cpu to interface with the external world, or provide functions on-chip that otherwise were to be added externally in the respective system. the c167cs generic peripherals are: ? two general purpose timer blocks (gpt1 and gpt2) ? two serial interfaces (asc0 and ssc) ? a watchdog timer ? two 16-channel capture/compare units (capcom1 and capcom2) ? a 4-channel pulse width modulation unit ? a 10-bit analog/digital converter ? a real time clock ? nine io ports with a total of 111 io lines each peripheral also contains a set of special function registers (sfrs), which control the functionality of the peripheral and temporarily store intermediate data results. each peripheral has an associated set of status flags. individually selected clock signals are generated for each peripheral from binary multiples of the cpu clock. peripheral interfaces the on-chip peripherals generally have two different types of interfaces, an interface to the cpu and an interface to external hardware. communication between cpu and peripherals is performed through special function registers (sfrs) and interrupts. the sfrs serve as control/status and data registers for the peripherals. interrupt requests are generated by the peripherals based on specific events which occur during their operation (e.g. operation complete, error, etc.). for interfacing with external hardware, specific pins of the parallel ports are used, when an input or output function has been selected for a peripheral. during this time, the port pins are controlled by the peripheral (when used as outputs) or by the external hardware which controls the peripheral (when used as inputs). this is called the alternate (input or output) function of a port pin, in contrast to its function as a general purpose io pin.
c167cs derivatives architectural overview users manual 2-12 v2.0, 2000-07 peripheral timing internal operation of cpu and peripherals is based on the cpu clock ( f cpu ). the on-chip oscillator derives the cpu clock from the crystal or from the external clock signal. the clock signal which is gated to the peripherals is independent from the clock signal which feeds the cpu. during idle mode the cpus clock is stopped while the peripherals continue their operation. peripheral sfrs may be accessed by the cpu once per state. when an sfr is written to by software in the same state where it is also to be modified by the peripheral, the software write operation has priority. further details on peripheral timing are included in the specific sections about each peripheral. programming hints access to sfrs all sfrs reside in data page 3 of the memory space. the following addressing mechanisms allow to access the sfrs: ? indirect or direct addressing with 16-bit (mem) addresses must guarantee that the used data page pointer (dpp0 dpp3) selects data page 3. ? accesses via the peripheral event controller ( pec ) use the srcpx and dstpx pointers instead of the data page pointers. ? short 8-bit (reg) addresses to the standard sfr area do not use the data page pointers but directly access the registers within this 512 byte area. ? short 8-bit (reg) addresses to the extended esfr area require switching to the 512 byte extended sfr area. this is done via the extension instructions extr, extp(r), exts(r). byte write operations to word wide sfrs via indirect or direct 16-bit (mem) addressing or byte transfers via the pec force zeros in the non-addressed byte. byte write operations via short 8-bit (reg) addressing can only access the low byte of an sfr and force zeros in the high byte. it is therefore recommended, to use the bit field instructions (bfldl and bfldh) to write to any number of bits in either byte of an sfr without disturbing the non-addressed byte and the unselected bits. reserved bits some of the bits which are contained in the c167css sfrs are marked as reserved. user software should never write 1s to reserved bits. these bits are currently not implemented and may be used in future products to invoke new functions. in this case, the active state for these functions will be 1, and the inactive state will be 0. therefore writing only 0s to reserved locations provides portability of the current software to future devices. after read accesses reserved bits should be ignored or masked out.
c167cs derivatives architectural overview users manual 2-13 v2.0, 2000-07 serial channels serial communication with other microcontrollers, processors, terminals or external peripheral components is provided by two serial interfaces with different functionality, an asynchronous/synchronous serial channel ( asc0 ) and a high-speed synchronous serial channel ( ssc ). the asc0 is upward compatible with the serial ports of the infineon 8-bit microcontroller families. it supports full-duplex asynchronous communication at up to 780/1030 kbaud and half-duplex synchronous communication at up to 3.1/4.1 mbaud @ 25/33 mhz cpu clock. a dedicated baud rate generator allows to set up all standard baud rates without oscillator tuning. for transmission, reception and error handling 4 separate interrupt vectors are provided. in asynchronous mode, 8- or 9-bit data frames are transmitted or received, preceded by a start bit and terminated by one or two stop bits. for multiprocessor communication, a mechanism to distinguish address from data bytes has been included (8-bit data plus wake up bit mode). in synchronous mode, the asc0 transmits or receives bytes (8 bits) synchronously to a shift clock which is generated by the asc0. the asc0 always shifts the lsb first. a loop back option is available for testing purposes. a number of optional hardware error detection capabilities has been included to increase the reliability of data transfers. a parity bit can automatically be generated on transmission or be checked on reception. framing error detection allows to recognize data frames with missing stop bits. an overrun error will be generated, if the last character received has not been read out of the receive buffer register at the time the reception of a new character is complete. the ssc supports full-duplex synchronous communication at up to 6.25/8.25 mbaud @ 25/33 mhz cpu clock. it may be configured so it interfaces with serially linked peripheral components. a dedicated baud rate generator allows to set up all standard baud rates without oscillator tuning. for transmission, reception and error handling 3 separate interrupt vectors are provided. the ssc transmits or receives characters of 2 16-bits length synchronously to a shift clock which can be generated by the ssc (master mode) or by an external master (slave mode). the ssc can start shifting with the lsb or with the msb and allows the selection of shifting and latching clock edges as well as the clock polarity. a number of optional hardware error detection capabilities has been included to increase the reliability of data transfers. transmit and receive error supervise the correct handling of the data buffer. phase and baudrate error detect incorrect serial data.
c167cs derivatives architectural overview users manual 2-14 v2.0, 2000-07 the on-chip can modules the integrated can modules (can1, can2) handle the completely autonomous transmission and reception of can frames in accordance with the can specification v2.0 part b (active), i.e. the on-chip can module can receive and transmit standard frames with 11-bit identifiers as well as extended frames with 29-bit identifiers. the modules provide full can functionality on up to 15 message objects (up to 30 objects if both modules are connected to the same physical bus). message object 15 may be configured for basic can functionality. both modes provide separate masks for acceptance filtering which allows to accept a number of identifiers in full can mode and also allows to disregard a number of identifiers in basic can mode. all message objects can be updated independent from the other objects and are equipped for the maximum message length of 8 bytes. the bit timing is derived from the xclk and is programmable up to a data rate of 1 mbaud. each can module uses two pins (configurable, both modules may use the same pair of pins) to interface to a bus transceiver. parallel ports the c167cs provides up to 111 io lines which are organized into eight input/output ports and one input port. all port lines are bit-addressable, and all input/output lines are individually (bit-wise) programmable as inputs or outputs via direction registers. the io ports are true bidirectional ports which are switched to high impedance state when configured as inputs. the output drivers of six io ports can be configured (pin by pin) for push/pull operation or open-drain operation via control registers. during the internal reset, all port pins are configured as inputs. all port lines have programmable alternate input or output functions associated with them. port0 and port1 may be used as address and data lines when accessing external memory, while port 4 outputs the additional segment address bits a23/19/17 a16 in systems where segmentation is used to access more than 64 kbytes of memory. port 6 provides the optional bus arbitration signals (breq , hlda , hold ) and the chip select signals cs4 cs0 . port 2 accepts the fast external interrupt inputs and provides inputs/outputs for the capcom1 unit. port 3 includes alternate functions of timers, serial interfaces, the optional bus control signal bhe , and the system clock output (clkout/ fout). port 5 is used for timer control signals and for the analog inputs to the a/d converter. the analog extension channels are connected via p1l. port 7 provides the output signals from the pwm unit and inputs/outputs for the capcom2 unit (more on p1h). port 8 provides inputs/outputs for the capcom2 unit. four pins of port1 may also be used as inputs/outputs for the capcom2 unit. all port lines that are not used for these alternate functions may be used as general purpose io lines.
c167cs derivatives architectural overview users manual 2-15 v2.0, 2000-07 a/d converter for analog signal measurement, a 10-bit a/d converter with 24 multiplexed input channels and a sample and hold circuit has been integrated on-chip. it uses the method of successive approximation. the sample time (for loading the capacitors) and the conversion time is programmable and can so be adjusted to the external circuitry. overrun error detection/protection is provided for the conversion result register (addat): either an interrupt request will be generated when the result of a previous conversion has not been read from the result register at the time the next conversion is complete, or the next conversion is suspended in such a case until the previous result has been read. for applications which require less analog input channels, the remaining channel inputs can be used as digital input (or io) port pins. the a/d converter of the c167cs supports four different conversion modes. in the standard single channel conversion mode, the analog level on a specified channel is sampled once and converted to a digital result. in the single channel continuous mode, the analog level on a specified channel is repeatedly sampled and converted without software intervention. in the auto scan mode, the analog levels on a prespecified number of channels are sequentially sampled and converted. in the auto scan continuous mode, the number of prespecified channels is repeatedly sampled and converted. in addition, the conversion of a specific channel can be inserted (injected) into a running sequence without disturbing this sequence. this is called channel injection mode. the peripheral event controller (pec) may be used to automatically store the conversion results into a table in memory for later evaluation, without requiring the overhead of entering and exiting interrupt routines for each data transfer. real time clock the c167cs contains a real time clock (rtc) which serves for different purposes: ? system clock to determine the current time and date, even during idle mode and power down mode (optionally) ? cyclic time based interrupt, e.g. to provide a system time tick independent of the cpu frequency without loading the general purpose timers, or to wake up regularly from idle mode. ? 48-bit timer for long term measurements, the maximum usable timespan is more than 100 years. the rtc module consists of a chain of 3 divider blocks, a fixed 8:1 divider, the reloadable 16-bit timer t14 and the 32-bit rtc timer (accessible via registers rtch and rtcl). both timers count up.
c167cs derivatives architectural overview users manual 2-16 v2.0, 2000-07 general purpose timer (gpt) unit the gpt units represent a very flexible multifunctional timer/counter structure which may be used for many different time related tasks such as event timing and counting, pulse width and duty cycle measurements, pulse generation, or pulse multiplication. the five 16-bit timers are organized in two separate modules, gpt1 and gpt2. each timer in each module may operate independently in a number of different modes, or may be concatenated with another timer of the same module. each timer can be configured individually for one of four basic modes of operation, which are timer, gated timer, counter mode and incremental interface mode (gpt1 timers). in timer mode the input clock for a timer is derived from the internal cpu clock divided by a programmable prescaler, while counter mode allows a timer to be clocked in reference to external events (via txin). pulse width or duty cycle measurement is supported in gated timer mode where the operation of a timer is controlled by the gate level on its external input pin txin. in incremental interface mode the gpt1 timers can be directly connected to the incremental position sensor signals a and b via the respective inputs txin and txeud. direction and count signals are internally derived from these two input signals, so the contents of timer tx corresponds to the sensor position. the third position sensor signal top0 can be connected to an interrupt input. the count direction (up/down) for each timer is programmable by software or may additionally be altered dynamically by an external signal (txeud) to facilitate e.g. position tracking. the core timers t3 and t6 have output toggle latches (txotl) which change their state on each timer over-flow/underflow. the state of these latches may be output on port pins (txout) or may be used internally to concatenate the core timers with the respective auxiliary timers resulting in 32/33-bit timers/counters for measuring long time periods with high resolution. various reload or capture functions can be selected to reload timers or capture a timers contents triggered by an external signal or a selectable transition of toggle latch txotl. the maximum resolution of the timers in module gpt1 is 8 cpu clock cycles (= 16 tcl). with their maximum resolution of 4 cpu clock cycles (= 8 tcl) the gpt2 timers provide precise event control and time measurement.
c167cs derivatives architectural overview users manual 2-17 v2.0, 2000-07 capture/compare (capcom) units the two capcom units support generation and control of timing sequences on up to 32 channels with a maximum resolution of 8 cpu clock cycles. the capcom units are typically used to handle high speed io tasks such as pulse and waveform generation, pulse width modulation (pwm), digital to analog (d/a) conversion, software timing, or time recording relative to external events. four 16-bit timers (t0/t1, t7/t8) with reload registers provide two independent time bases for the capture/compare register array. the input clock for the timers is programmable to several prescaled values of the internal cpu clock, or may be derived from an overflow/underflow of timer t6 in module gpt2. this provides a wide range of variation for the timer period and resolution and allows precise adjustments to the application specific requirements. in addition, external count inputs for capcom timers t0 and t7 allow event scheduling for the capture/compare registers relative to external events. both of the two capture/compare register arrays contain 16 dual purpose capture/ compare registers, each of which may be individually allocated to either capcom timer t0 or t1 (t7 or t8, respectively), and programmed for capture or compare function. each register has one port pin associated with it which serves as an input pin for triggering the capture function, or as an output pin to indicate the occurrence of a compare event. when a capture/compare register has been selected for capture mode, the current contents of the allocated timer will be latched (captured) into the capture/compare register in response to an external event at the port pin which is associated with this register. in addition, a specific interrupt request for this capture/compare register is generated. either a positive, a negative, or both a positive and a negative external signal transition at the pin can be selected as the triggering event. the contents of all registers which have been selected for one of the five compare modes are continuously compared with the contents of the allocated timers. when a match occurs between the timer value and the value in a capture/compare register, specific actions will be taken based on the selected compare mode. pulse width modulation unit the pwm unit supports the generation of up to four independent high-speed pwm signals. it allows to generate standard (edge aligned) pwm signals as well as symmetrical (center aligned) pwm signals. in burst mode two channels may be combined with their output signals anded, where one channel gates the output signal of the other channel. single shot mode allows to generate single output pulses (retriggerable) under software control. each pwm channel is controlled by an up/down counter with associated reload and compare registers. the polarity of the pwm output signals may be controlled via the respective port output latch (combination via exor).
c167cs derivatives architectural overview users manual 2-18 v2.0, 2000-07 watchdog timer the watchdog timer represents one of the fail-safe mechanisms which have been implemented to prevent the controller from malfunctioning for longer periods of time. the watchdog timer is always enabled after a reset of the chip, and can only be disabled in the time interval until the einit (end of initialization) instruction has been executed. thus, the chips start-up procedure is always monitored. the software has to be designed to service the watchdog timer before it overflows. if, due to hardware or software related failures, the software fails to do so, the watchdog timer overflows and generates an internal hardware reset and pulls the rstout pin low in order to allow external hardware components to reset. the watchdog timer is a 16-bit timer, clocked with the cpu clock divided by 2, 4, 128, or 256. the high byte of the watchdog timer register can be set to a prespecified reload value (stored in wdtrel) in order to allow further variation of the monitored time interval. each time it is serviced by the application software, the high byte of the watchdog timer is reloaded. thus, time intervals between 21 m s and 671 ms can be monitored @ 25 mhz (16 m s and 335 ms @ 33 mhz). the default watchdog timer interval after reset is 5.2/4.0 ms (@ 25/33 mhz). 2.4 power management features the known basic power reduction modes (idle and power down) are enhanced by a number of additional power management features (see below). these features can be combined to reduce the controllers power consumption to the respective applications possible minimum. ? flexible clock generation ? flexible peripheral management (peripherals can be enabled/disabled separately or in groups) ? periodic wakeup from idle mode via rtc timer the listed features provide effective means to realize standby conditions for the system with an optimum balance between power reduction (i.e. standby time) and peripheral operation (i.e. system functionality). flexible clock generation the flexible clock generation system combines a variety of improved mechanisms (partly user controllable) to provide the c167cs modules with clock signals. this is especially important in power sensitive modes like standby operation. the power optimized oscillator generally reduces the amount of power which is consumed in order to generate the clock signal within the c167cs. the clock system efficiently controls the amount of power which is consumed in order to distribute the clock signal within the c167cs.
c167cs derivatives architectural overview users manual 2-19 v2.0, 2000-07 slowdown operation is achieved by dividing the oscillator clock by a programmable factor (1 32) resulting in a low frequency device operation which significantly reduces the overall power consumption. flexible peripheral management the flexible peripheral management provides a mechanism to enable and disable each peripheral module separately. in each situation (e.g. several system operating modes, standby, etc.) only those peripherals may be kept running which are required for the respective functionality. all others can be switched off. it also allows the operation control of whole groups of peripherals including the power required for generating and distributing their clock input signal. other peripherals may remain active, e.g. in order to maintain communication channels. the registers of separately disabled peripherals (not within a disabled group) can still be accessed. periodic wakeup from idle mode periodic wakeup from idle mode combines the drastically reduced power consumption in idle mode (in conjunction with the additional power management features) with a high level of system availability. external signals and events can be scanned (at a lower rate) by periodically activating the cpu and selected peripherals which then return to powersave mode after a short time. this greatly reduces the systems average power consumption. 2.5 protected bits the c167cs provides a special mechanism to protect bits which can be modified by the on-chip hardware from being changed unintentionally by software accesses to related bits (see also chapter 4 ). the following bits are protected:
c167cs derivatives architectural overview users manual 2-20 v2.0, 2000-07 s = 135 protected bits. table 2-1 c167cs protected bits register bit name notes t2ic, t3ic, t4ic t2ir, t3ir, t4ir gpt1 timer interrupt request flags t5ic, t6ic t5ir, t6ir gpt2 timer interrupt request flags cric crir gpt2 caprel interrupt request flag t3con, t6con t3otl, t6otl gptx timer output toggle latches t0ic, t1ic t0ir, t1ir capcom1 timer interrupt request flags t7ic, t8ic t7ir, t8ir capcom2 timer interrupt request flags s0tic, s0tbic s0tir, s0tbir asc0 transmit(buffer) interrupt request flags s0ric, s0eic s0rir, s0eir asc0 receive/error interrupt request flags s0con s0ren asc0 receiver enable flag ssctic, sscric ssctir, sscrir ssc transmit/receive interrupt request flags ssceic ssceir ssc error interrupt request flag ssccon sscbsy ssc busy flag ssccon sscbe, sscpe ssc error flags ssccon sscre, sscte ssc error flags adcic, adeic adcir, adeir adc end-of-conv./overrun intr. request flag adcon adst, adcrq adc start flag/injection request flag cc31ic cc16ic cc31ir cc16ir capcom2 interrupt request flags cc15ic cc0ic cc15ir cc0ir capcom1 interrupt request flags pwmic pwmir pwm module interrupt request flag pwmcon0 pir3 ptr0 all bits of pwmcon0 pwmcon1 ps3 pen0 all bits of pwmcon1 tfr tfr.15,14,13 class a trap flags tfr tfr.7,3,2,1,0 class b trap flags p2 p2.15 p2.0 all bits of port 2 p7 p7.7 p7.0 all bits of port 7 p8 p8.7 p8.0 all bits of port 8 xp3ic xp0ic xp3ir xp0ic x-peripheral interrupt request flags isnc rtcir, pllir interrupt node sharing request flags
c167cs derivatives memory organization users manual 3-1 v2.0, 2000-07 3 memory organization the memory space of the c167cs is configured in a von neumann architecture. this means that code and data are accessed within the same linear address space. all of the physically separated memory areas, including internal rom/flash/otp (where integrated), internal ram, the internal special function register areas (sfrs and esfrs), the address areas for integrated xbus peripherals and external memory are mapped into one common address space. the c167cs provides a total addressable memory space of 16 mbytes. this address space is arranged as 256 segments of 64 kbytes each, and each segment is again subdivided into four data pages of 16 kbytes each (see figure 3-1 ). figure 3-1 address space overview mca04325 begin of prog. memory above 32 kb 255 128 254...129 127 126...65 64 63 62...12 11 10 9 8 7 6 5 4 3 2 1 0 internal rom area 000000 h 01ffff h 0affff h 400000 h 800000 h ffffff h data page 2 data page 3 alternate rom area 255...2 02ffff h 080000 h 000000 h 010000 h 018000 h 01ffff h segment 0 segment 1 16 mbyte external addressing capability total address space 16 mbyte, segments 255...0 segments 1 and 0 64 + 64 kbyte
c167cs derivatives memory organization users manual 3-2 v2.0, 2000-07 most internal memory areas are mapped into segment 0, the system segment. the upper 4 kbyte of segment 0 (00f000 h 00ffff h ) hold the internal ram and special function register areas (sfr and esfr). the lower 32 kbyte of segment 0 (000000 h 007fff h ) may be occupied by a part of the on-chip rom/flash/otp memory and is called the internal rom area. this rom area can be remapped to segment 1 (010000 h 017fff h ), to enable external memory access in the lower half of segment 0, or the internal rom may be disabled at all. code and data may be stored in any part of the internal memory areas, except for the sfr blocks, which may be used for control/data, but not for instructions. note: accesses to the internal rom area on romless devices will produce unpredictable results. bytes are stored at even or odd byte addresses. words are stored in ascending memory locations with the low byte at an even byte address being followed by the high byte at the next odd byte address. double words (code only) are stored in ascending memory locations as two subsequent words. single bits are always stored in the specified bit position at a word address. bit position 0 is the least significant bit of the byte at an even byte address, and bit position 15 is the most significant bit of the byte at the next odd byte address. bit addressing is supported for a part of the special function registers, a part of the internal ram and for the general purpose registers. figure 3-2 storage of words, bytes, and bits in a byte organized memory note: byte units forming a single word or a double word must always be stored within the same physical (internal, external, rom, ram) and organizational (page, segment) memory area. mcd01996 15 14 8 0 6 7 h xxxx6 bits bits byte byte word (high byte) word (low byte) xxxx5 h xxxx4 h xxxx3 h xxxx2 h xxxx1 h xxxx0 h xxxxf h
c167cs derivatives memory organization users manual 3-3 v2.0, 2000-07 3.1 internal rom area the c167cs may reserve an address area of variable size (depending on the version) for on-chip mask-programmable rom/flash/otp memory (organized as x 32). the lower 32 kbyte of this on-chip memory block are referred to as internal rom area. internal rom accesses are globally enabled or disabled via bit romen in register syscon. this bit is set during reset according to the level on pin ea , or may be altered via software. if enabled, the internal rom area occupies the lower 32 kbyte of either segment 0 or segment 1 (alternate rom area). this mapping is controlled by bit roms1 in register syscon. note: the size of the internal rom area is independent of the size of the actual implemented program memory. also devices with less than 32 kbyte of program memory or with no program memory at all will have this 32 kbyte area occupied, if the program memory is enabled. devices with a larger program memory provide the mapping option only for the internal rom area. devices with a program memory size above 32 kbyte expand the rom area from the middle of segment 1, i.e. starting at address 018000 h . the internal program memory can be used for both code (instructions) and data (constants, tables, etc.) storage. code fetches are always made on even byte addresses. the highest possible code storage location in the internal program memory is either xxxxfe h for single word instructions, or xxxxfc h for double word instructions. the respective location must contain a branch instruction (unconditional), because sequential boundary crossing from internal program memory to external memory is not supported and causes erroneous results. any word and byte data read accesses may use the indirect or long 16-bit addressing modes. there is no short addressing mode for internal rom operands. any word data access is made to an even byte address. the highest possible word data storage location in the internal rom is xxxxfe h . for pec data transfers the internal program memory can be accessed independent of the contents of the dpp registers via the pec source and destination pointers. the internal program memory is not provided for single bit storage, and therefore it is not bit addressable. note: the x in the locations above depend on the available program memory and on the mapping. the internal rom may be enabled, disabled or mapped into segment 0 or segment 1 under software control. chapter 22 shows how to do this and reminds of the precautions that must be taken in order to prevent the system from crashing.
c167cs derivatives memory organization users manual 3-4 v2.0, 2000-07 3.2 internal ram and sfr area the ram/sfr area is located within data page 3 and provides access to the internal ram (iram, organized as x 16) and to two 512 byte blocks of special function registers (sfrs). the c167cs provides 3 kbyte of iram. figure 3-3 system memory map mca04424 xram 008000 h 00e000 h reserved can1 esfr area iram ext. memory xram x-peripherals iram/sfr sfr area 00e7ff h 00ef00 h 00f000 h 00f200 h 00ffff h 00ffff h 00f000 h 00c000 h data page 3 data page 2 note: new xbus peripherals will be preferably placed into the shaded areas, which now access external memory (bus cycles executed). reserved xram 00e000 h 00d7ff h can2 00ee00 h
c167cs derivatives memory organization users manual 3-5 v2.0, 2000-07 note: the upper 256 bytes of sfr area, esfr area and internal ram are bit- addressable (see shaded blocks in figure 3-3 ). code accesses are always made on even byte addresses. the highest possible code storage location in the internal ram is either 00fdfe h for single word instructions or 00fdfc h for double word instructions. the respective location must contain a branch instruction (unconditional), because sequential boundary crossing from internal ram to the sfr area is not supported and causes erroneous results. any word and byte data in the internal ram can be accessed via indirect or long 16-bit addressing modes, if the selected dpp register points to data page 3. any word data access is made on an even byte address. the highest possible word data storage location in the internal ram is 00fdfe h . for pec data transfers, the internal ram can be accessed independent of the contents of the dpp registers via the pec source and destination pointers. the upper 256 byte of the internal ram (00fd00 h through 00fdff h ) and the gprs of the current bank are provided for single bit storage, and thus they are bitaddressable. system stack the system stack may be defined within the internal ram. the size of the system stack is controlled by bitfield stksz in register syscon (see table 3-1 ). for all system stack operations the on-chip ram is accessed via the stack pointer (sp) register. the stack grows downward from higher towards lower ram address locations. only word accesses are supported to the system stack. a stack overflow (stkov) and a stack underflow (stkun) register are provided to control the lower and upper limits of the selected stack area. these two stack boundary registers can be used not only for protection against data destruction, but also allow to implement a circular stack with hardware supported system stack flushing and filling (except for option 111). the technique of implementing this circular stack is described in chapter 22 . table 3-1 system stack size encoding stack size (words) internal ram addresses (words) 0 0 0 b 256 00fbfe h 00fa00 h (default after reset) 0 0 1 b 128 00fbfe h 00fb00 h 0 1 0 b 64 00fbfe h 00fb80 h 0 1 1 b 32 00fbfe h 00fbc0 h 1 0 0 b 512 00fbfe h 00f800 h 1 0 1 b C reserved. do not use this combination. 1 1 0 b C reserved. do not use this combination. 1 1 1 b 1536 00fdfe h 00f200 h (note: no circular stack)
c167cs derivatives memory organization users manual 3-6 v2.0, 2000-07 general purpose registers the general purpose registers (gprs) use a block of 16 consecutive words within the internal ram. the context pointer (cp) register determines the base address of the currently active register bank. this register bank may consist of up to 16 word-gprs (r0, r1, r15) and/or of up to 16 byte-gprs (rl0, rh0, rl7, rh7). the sixteen byte-gprs are mapped onto the first eight word-gprs (see table 3-2 ). in contrast to the system stack, a register bank grows from lower towards higher address locations and occupies a maximum space of 32 byte. the gprs are accessed via short 2-, 4-, or 8-bit addressing modes using the context pointer (cp) register as base address (independent of the current dpp register contents). additionally, each bit in the currently active register bank can be accessed individually. the c167cs supports fast register bank (context) switching. multiple register banks can physically exist within the internal ram at the same time. only the register bank selected by the context pointer register (cp) is active at a given time, however. selecting a new active register bank is simply done by updating the cp register. a particular switch context (scxt) instruction performs register bank switching and an automatic saving of table 3-2 mapping of general purpose registers to ram addresses internal ram address byte registers word register + 1e h Cr15 + 1c h Cr14 + 1a h Cr13 + 18 h Cr12 + 16 h Cr11 + 14 h Cr10 + 12 h Cr9 + 10 h Cr8 + 0e h rh7 rl7 r7 + 0c h rh6 rl6 r6 + 0a h rh5 rl5 r5 + 08 h rh4 rl4 r4 + 06 h rh3 rl3 r3 + 04 h rh2 rl2 r2 + 02 h rh1 rl1 r1 + 00 h rh0 rl0 r0
c167cs derivatives memory organization users manual 3-7 v2.0, 2000-07 the previous context. the number of implemented register banks (arbitrary sizes) is only limited by the size of the available internal ram. details on using, switching and overlapping register banks are described in chapter 22 . pec source and destination pointers the 16 word locations in the internal ram from 00fce0 h to 00fcfe h (just below the bit-addressable section) are provided as source and destination address pointers for data transfers on the eight pec channels. each channel uses a pair of pointers stored in two subsequent word locations with the source pointer (srcpx) on the lower and the destination pointer (dstpx) on the higher word address (x = 7 0). figure 3-4 location of the pec pointers whenever a pec data transfer is performed, the pair of source and destination pointers, which is selected by the specified pec channel number, is accessed independent of the current dpp register contents and also the locations referred to by these pointers are accessed independent of the current dpp register contents. if a pec channel is not used, the corresponding pointer locations area available and can be used for word or byte data storage. for more details about the use of the source and destination pointers for pec data transfers see chapter 5 . 00'fce2 00'fce0 h h srcp0 dstp0 00'f5fe 00'f600 mcd03903 h h destination 00'fcfc pointers and h pec source srcp7 00'fcfe h dstp7 internal 00'fce0 00'fcde ram h h 00'fcfe 00'fd00 h h
c167cs derivatives memory organization users manual 3-8 v2.0, 2000-07 special function registers the functions of the cpu, the bus interface, the io ports and the on-chip peripherals of the c167cs are controlled via a number of so-called special function registers (sfrs). these sfrs are arranged within two areas of 512 byte size each. the first register block, the sfr area, is located in the 512 bytes above the internal ram (00ffff h 00fe00 h ), the second register block, the extended sfr (esfr) area, is located in the 512 bytes below the internal ram (00f1ff h 00f000 h ). special function registers can be addressed via indirect and long 16-bit addressing modes. using an 8-bit offset together with an implicit base address allows to address word sfrs and their respective low bytes. however, this does not work for the respective high bytes! note: writing to any byte of an sfr causes the non-addressed complementary byte to be cleared! the upper half of each register block is bit-addressable, so the respective control/status bits can directly be modified or checked using bit addressing. when accessing registers in the esfr area using 8-bit addresses or direct bit addressing, an extend register (extr) instruction is required before, to switch the short addressing mechanism from the standard sfr area to the extended sfr area. this is not required for 16-bit and indirect addresses. the gprs r15 r0 are duplicated, i.e. they are accessible within both register blocks via short 2-, 4- or 8-bit addresses without switching. esfr_switch_example: extr #4 ;switch to esfr area for next 4 instr. mov odp2, #data16 ;odp2 uses 8-bit reg addressing bfldl dp6, #mask, #data8 ;bit addressing for bit fields bset dp1h.7 ;bit addressing for single bits mov t8rel, r1 ;t8rel uses 16-bit mem address, ;r1 is duplicated into the esfr space ;(extr is not required for this access) ;---- ;----------------- ;the scope of the extr #4 instruction ; ends here! mov t8rel, r1 ;t8rel uses 16-bit mem address, ;r1 is accessed via the sfr space in order to minimize the use of the extr instructions the esfr area mostly holds registers which are mainly required for initialization and mode selection. registers that need to be accessed frequently are allocated to the standard sfr area, wherever possible. note: the tools are equipped to monitor accesses to the esfr area and will automatically insert extr instructions, or issue a warning in case of missing or excessive extr instructions.
c167cs derivatives memory organization users manual 3-9 v2.0, 2000-07 3.3 the on-chip xram the c167cs provides access to 8 kbyte of on-chip extension ram. the xram is located within data page 3 and is split into two xram areas of 2 kbyte and 6 kbyte (organized as 1 k 16 and 3 k 16). as the xram is connected to the internal xbus it is accessed like external memory, however, no external bus cycles are executed for these accesses. xram accesses are globally enabled or disabled via bit xpen in register syscon. this bit is cleared after reset and may be set via software during the initialization to allow accesses to the on-chip xram. when the xram is disabled (default after reset) all accesses to the xram area are mapped to external locations. the xram may be used for both code (instructions) and data (variables, user stack, tables, etc.) storage. code fetches are always made on even byte addresses. the highest possible code storage location in the xram is either 00e7fe h /00d7fe h for single word instructions, or 00e7fc h /00d7fc h for double word instructions. the respective location must contain a branch instruction (unconditional), because sequential boundary crossing from xram to external memory is not supported and causes erroneous results. any word and byte data read accesses may use the indirect or long 16-bit addressing modes. there is no short addressing mode for xram operands. any word data access is made to an even byte address. the highest possible word data storage location in the xram is 00e7fe h /00d7fe h . for pec data transfers the xram can be accessed independent of the contents of the dpp registers via the pec source and destination pointers. note: as the xram appears like external memory it cannot be used for the c167css system stack or register banks. the xram is not provided for single bit storage and therefore is not bitaddressable. the on-chip xram is accessed with the following bus cycles: ? normal ale ? no cycle time waitstates (no ready control) ? no tristate time waitstate ? no read/write delay ? 16-bit demultiplexed bus cycles (4 tcl) even if the xram is used like external memory it does not occupy busconx/ addrselx registers but rather is selected via additional dedicated xbcon/xadrs registers. these registers are mask-programmed and are not user accessible. with these registers the address areas 00e000 h to 00e7ff h and 00c000 h to 00dfff h are reserved for xram accesses. note: the 6 kbyte xram area only covers locations 00c000 h to 00d7ff h . the address decoder, however, reserves 2 13 kbytes, i.e. locations 00c000 h to 00dfff h .
c167cs derivatives memory organization users manual 3-10 v2.0, 2000-07 xram access via external masters in x-peripheral share mode (bit xper-share in register syscon is set) the on-chip xram of the c167cs can be accessed by an external master during hold mode via the c167css bus interface. these external accesses must use the same configuration as internally programmed (see above). no waitstates are required. in x-peripheral share mode the c167cs bus interface reverses its direction, i.e. address lines (port1, port 4), control signals (rd , wr ), and bhe must be driven by the external master. note: the configuration in register syscon cannot be changed after the execution of the einit instruction.
c167cs derivatives memory organization users manual 3-11 v2.0, 2000-07 3.4 external memory space the c167cs is capable of using an address space of up to 16 mbyte. only parts of this address space are occupied by internal memory areas. all addresses which are not used for on-chip memory (rom/flash/otp or ram) or for registers may reference external memory locations. this external memory is accessed via the c167css external bus interface. four memory bank sizes are supported: ? non-segmented mode: 64 kbyte with a15 a0 on port0 or port1 ? 2-bit segmented mode: 256 kbyte with a17 a16 on port 4 and a15 a0 on port0 or port1 ? 4-bit segmented mode: 1 mbyte with a19 a16 on port 4 and a15 a0 on port0 or port1 ? 8-bit segmented mode: 16 mbyte with a22 a16 on port 4 and a15 a0 on port0 or port1 each bank can be directly addressed via the address bus, while the programmable chip select signals can be used to select various memory banks. the c167cs also supports four different bus types : ? multiplexed 16-bit bus with address and data on port0 (default after reset) ? multiplexed 8-bit bus with address and data on port0/p0l ? demultiplexed 16-bit bus with address on port1 and data on port0 ? demultiplexed 8-bit bus with address on port1 and data on p0l memory model and bus mode are selected during reset by pin ea and port0 pins. for further details about the external bus configuration and control please refer to chapter 9 . external word and byte data can only be accessed via indirect or long 16-bit addressing modes using one of the four dpp registers. there is no short addressing mode for external operands. any word data access is made to an even byte address. for pec data transfers the external memory in segment 0 can be accessed independent of the contents of the dpp registers via the pec source and destination pointers. the external memory is not provided for single bit storage and therefore it is not bitaddressable.
c167cs derivatives memory organization users manual 3-12 v2.0, 2000-07 3.5 crossing memory boundaries the address space of the c167cs is implicitly divided into equally sized blocks of different granularity and into logical memory areas. crossing the boundaries between these blocks (code or data) or areas requires special attention to ensure that the controller executes the desired operations. memory areas are partitions of the address space that represent different kinds of memory (if provided at all). these memory areas are the internal ram/sfr area, the internal rom/flash/otp (if available), the on-chip x-peripherals (if integrated) and the external memory. accessing subsequent data locations that belong to different memory areas is no problem. however, when executing code , the different memory areas must be switched explicitly via branch instructions. sequential boundary crossing is not supported and leads to erroneous results. note: changing from the external memory area to the internal ram/sfr area takes place within segment 0. segments are contiguous blocks of 64 kbyte each. they are referenced via the code segment pointer csp for code fetches and via an explicit segment number for data accesses overriding the standard dpp scheme. during code fetching segments are not changed automatically, but rather must be switched explicitly. the instructions jmps, calls and rets will do this. in larger sequential programs make sure that the highest used code location of a segment contains an unconditional branch instruction to the respective following segment, to prevent the prefetcher from trying to leave the current segment. data pages are contiguous blocks of 16 kbyte each. they are referenced via the data page pointers dpp3 0 and via an explicit data page number for data accesses overriding the standard dpp scheme. each dpp register can select one of the possible 1024 data pages. the dpp register that is used for the current access is selected via the two upper bits of the 16-bit data address. subsequent 16-bit data addresses that cross the 16 kbyte data page boundaries therefore will use different data page pointers, while the physical locations need not be subsequent within memory.
c167cs derivatives memory organization users manual 3-13 v2.0, 2000-07 3.6 protection of the on-chip mask rom the on-chip mask rom of the c167cs can be protected against read accesses of both code and data. rom protection is established during the production process of the device (a rom mask can be ordered with a rom protection or without it). no software control is possible, i.e. the rom protection cannot be disabled or enabled by software. when a device has been produced with rom protection active, the rom contents are protected against unauthorized access by the following measures: ? no data read accesses to the internal rom by any instruction which is executed from any location outside the on-chip mask rom (including iram, xram, and external memory). a program cannot read any data out of the protected rom from outside. the read data will be replaced by the default value 009b h for any read access to any location. ? no codes fetches from the internal rom by any instruction which is executed from any location outside the on-chip mask rom (including iram, xram, and external memory). a program cannot branch to a location within the protected rom from outside. this applies to jumps as well as to returns, i.e. a called routine within ram or external memory can never return to the protected rom. the fetched code will be replaced by the default value 009bh for any access to any location. this default value will be decoded as the instruction trap #00 which will restart program execution at location 000000 h . note: rom protection may be used for applications where the complete software fits into the on-chip rom, or where the on-chip rom holds an initialization software which is then replaced by an external (e.g.) application software. in the latter case no data (constants, tables, etc.) can be stored within the rom. the rom itself should be mapped to segment 1 before branching outside, so an interrupt vector table can established in external memory.
c167cs derivatives the central processing unit (cpu) users manual 4-1 v2.0, 2000-07 4 the central processing unit (cpu) basic tasks of the cpu are to fetch and decode instructions, to supply operands for the arithmetic and logic unit (alu), to perform operations on these operands in the alu, and to store the previously calculated results. as the cpu is the main engine of the c167cs controller, it is also affected by certain actions of the peripheral subsystem. since a four stage pipeline is implemented in the c167cs, up to four instructions can be processed in parallel. most instructions of the c167cs are executed in one machine cycle (2 cpu clock periods) due to this parallelism. this chapter describes how the pipeline works for sequential and branch instructions in general, and which hardware provisions have been made to speed the execution of jump instructions in particular. the general instruction timing is described including standard and exceptional timing. while internal memory accesses are normally performed by the cpu itself, external peripheral or memory accesses are performed by a particular on-chip external bus controller (ebc), which is automatically invoked by the cpu whenever a code or data address refers to the external address space. figure 4-1 cpu block diagram mcb02147 cpu sp stkov stkun instr. reg. instr. ptr. exec. unit 4-stage pipeline mdh mdl psw syscon context ptr. mul/div-hw r15 r0 general purpose registers bit-mask gen barrel - shifter alu (16-bit) data page ptr. code seg. ptr. internal ram r15 r0 rom 16 16 32 buscon 0 buscon 1 buscon 2 buscon 3 buscon 4 addrsel 4 addrsel 3 addrsel 2 addrsel 1
c167cs derivatives the central processing unit (cpu) users manual 4-2 v2.0, 2000-07 if possible, the cpu continues operating while an external memory access is in progress. if external data are required but are not yet available, or if a new external memory access is requested by the cpu, before a previous access has been completed, the cpu will be held by the ebc until the request can be satisfied. the ebc is described in a dedicated chapter. the on-chip peripheral units of the c167cs work nearly independent of the cpu with a separate clock generator. data and control information is interchanged between the cpu and these peripherals via special function registers (sfrs). whenever peripherals need a non-deterministic cpu action, an on-chip interrupt controller compares all pending peripheral service requests against each other and prioritizes one of them. if the priority of the current cpu operation is lower than the priority of the selected peripheral request, an interrupt will occur. basically, there are two types of interrupt processing: ? standard interrupt processing forces the cpu to save the current program status and the return address on the stack before branching to the interrupt vector jump table. ? pec interrupt processing steals just one machine cycle from the current cpu activity to perform a single data transfer via the on-chip peripheral event controller (pec). system errors detected during program execution (so-called hardware traps) or an external non-maskable interrupt are also processed as standard interrupts with a very high priority. in contrast to other on-chip peripherals, there is a closer conjunction between the watchdog timer and the cpu. if enabled, the watchdog timer expects to be serviced by the cpu within a programmable period of time, otherwise it will reset the chip. thus, the watchdog timer is able to prevent the cpu from going totally astray when executing erroneous code. after reset, the watchdog timer starts counting automatically, but it can be disabled via software, if desired. beside its normal operation there are the following particular cpu states: ? reset state: any reset (hardware, software, watchdog) forces the cpu into a predefined active state. ? idle state: the clock signal to the cpu itself is switched off, while the clocks for the on-chip peripherals keep running. ? sleep state: all of the on-chip clocks are switched off (rtc clock selectable), wake- up via external interrupts or rtc. ? power down state: all of the on-chip clocks are switched off (rtc clock selectable), all inputs are disregarded. a transition into an active cpu state is forced by an interrupt (if being in idle or sleep) or by a reset (if being in power down mode). the idle, sleep, power down, and reset states can be entered by particular c167cs system control instructions.
c167cs derivatives the central processing unit (cpu) users manual 4-3 v2.0, 2000-07 a set of special function registers is dedicated to the functions of the cpu core: ? general system configuration: syscon (rp0h) ? cpu status indication and control: psw ? code access control: ip, csp ? data paging control: dpp0, dpp1, dpp2, dpp3 ? gprs access control: cp ? system stack access control: sp, stkun, stkov ? multiply and divide support: mdl, mdh, mdc ? alu constants support: zeros, ones 4.1 instruction pipelining the instruction pipeline of the c167cs partitiones instruction processing into four stages of which each one has its individual task: 1 st ? fetch: in this stage the instruction selected by the instruction pointer (ip) and the code segment pointer (csp) is fetched from either the internal rom, internal ram, or external memory. 2 nd ? decode: in this stage the instructions are decoded and, if required, the operand addresses are calculated and the respective operands are fetched. for all instructions, which implicitly access the system stack, the sp register is either decremented or incremented, as specified. for branch instructions the instruction pointer and the code segment pointer are updated with the desired branch target address (provided that the branch is taken). 3 rd ? execute: in this stage an operation is performed on the previously fetched operands in the alu. additionally, the condition flags in the psw register are updated as specified by the instruction. all explicit writes to the sfr memory space and all auto- increment or auto-decrement writes to gprs used as indirect address pointers are performed during the execute stage of an instruction, too. 4 th ? write back: in this stage all external operands and the remaining operands within the internal ram space are written back. a particularity of the c167cs are the so-called injected instructions. these injected instructions are generated internally by the machine to provide the time needed to process instructions, which cannot be processed within one machine cycle. they are automatically injected into the decode stage of the pipeline, and then they pass through the remaining stages like every standard instruction. program interrupts are performed by means of injected instructions, too. although these internally injected instructions will not be noticed in reality, they are introduced here to ease the explanation of the pipeline in the following.
c167cs derivatives the central processing unit (cpu) users manual 4-4 v2.0, 2000-07 sequential instruction processing each single instruction has to pass through each of the four pipeline stages regardless of whether all possible stage operations are really performed or not. since passing through one pipeline stage takes at least one machine cycle, any isolated instruction takes at least four machine cycles to be completed. pipelining, however, allows parallel (i.e. simultaneous) processing of up to four instructions. thus, most of the instructions seem to be processed during one machine cycle as soon as the pipeline has been filled once after reset (see figure 4-2 ). instruction pipelining increases the average instruction throughput considered over a certain period of time. in the following, any execution time specification of an instruction always refers to the average execution time due to pipelined parallel instruction processing. figure 4-2 sequential instruction pipelining standard branch instruction processing instruction pipelining helps to speed sequential program processing. in the case that a branch is taken, the instruction which has already been fetched providently is mostly not the instruction which must be decoded next. thus, at least one additional machine cycle is normally required to fetch the branch target instruction. this extra machine cycle is provided by means of an injected instruction (see figure 4-3 ). figure 4-3 standard branch instruction pipelining mct04327 fetch decode execute writeback i 1 i 2 i 1 i 3 i 2 i 1 i 4 i 3 i 2 i 1 i 5 i 4 i 3 i 2 i 6 i 5 i 4 i 3 1 machine cycle time mct04328 fetch decode execute writeback branch i n+2 i target ( i inject ) 1 machine cycle time branch branch branch i n i n i n ... ... ... i target+1 i target ( i inject ) i target+2 i target+1 ( i inject ) i target i target+2 i target+1 i target i target+3 injection
c167cs derivatives the central processing unit (cpu) users manual 4-5 v2.0, 2000-07 if a conditional branch is not taken, there is no deviation from the sequential program flow, and thus no extra time is required. in this case the instruction after the branch instruction will enter the decode stage of the pipeline at the beginning of the next machine cycle after decode of the conditional branch instruction. cache jump instruction processing the c167cs incorporates a jump cache to optimize conditional jumps, which are processed repeatedly within a loop. whenever a jump on cache is taken, the extra time to fetch the branch target instruction can be saved and thus the corresponding cache jump instruction in most cases takes only one machine cycle. this performance is achieved by the following mechanism: whenever a cache jump instruction passes through the decode stage of the pipeline for the first time (and provided that the jump condition is met), the jump target instruction is fetched as usual, causing a time delay of one machine cycle. in contrast to standard branch instructions, however, the target instruction of a cache jump instruction (jmpa, jmpr, jb, jbc, jnb, jnbs) is additionally stored in the cache after having been fetched. after each repeatedly following execution of the same cache jump instruction, the jump target instruction is not fetched from program memory but taken from the cache and immediately injected into the decode stage of the pipeline (see figure 4-4 ). a time saving jump on cache is always taken after the second and any further occurrence of the same cache jump instruction, unless an instruction which, has the fundamental capability of changing the csp register contents (jmps, calls, rets, trap, reti), or any standard interrupt has been processed during the period of time between two following occurrences of the same cache jump instruction. figure 4-4 cache jump instruction pipelining mct04329 fetch decode execute writeback i n+2 i target ( i inject ) 1 machine cycle 1st loop iteration cache jmp i n ... i target+1 i target injection ( i inject ) cache jmp cache jmp i n+2 i target+1 repeated loop iteration cache jmp i n ... i target+2 i target+1 injection of cached target instruction cache jmp cache jmp i target i n i target i n
c167cs derivatives the central processing unit (cpu) users manual 4-6 v2.0, 2000-07 4.2 particular pipeline effects since up to four different instructions are processed simultaneously, additional hardware has been spent in the c167cs to consider all causal dependencies which may exist on instructions in different pipeline stages without a loss of performance. this extra hardware (i.e. for forwarding operand read and write values) resolves most of the possible conflicts (e.g. multiple usage of buses) in a time optimized way and thus avoids that the pipeline becomes noticeable for the user in most cases. however, there are some very rare cases, where the circumstance that the c167cs is a pipelined machine requires attention by the programmer. in these cases the delays caused by pipeline conflicts can be used for other instructions in order to optimize performance. context pointer updating an instruction, which calculates a physical gpr operand address via the cp register, is mostly not capable of using a new cp value, which is to be updated by an immediately preceding instruction. thus, to make sure that the new cp value is used, at least one instruction must be inserted between a cp-changing and a subsequent gpr-using instruction, as shown in the following example: i n :scxt cp,#0fc00h ;select a new context i n + 1 : ;must not be an instruction using a gpr i n + 2 :mov r0,#datax ;write to gpr 0 in the new context data page pointer updating an instruction, which calculates a physical operand address via a particular dppn (n = 0 to 3) register, is mostly not capable of using a new dppn register value, which is to be updated by an immediately preceding instruction. thus, to make sure that the new dppn register value is used, at least one instruction must be inserted between a dppn- changing instruction and a subsequent instruction which implicitly uses dppn via a long or indirect addressing mode, as shown in the following example: i n :mov dpp0,#4 ;select data page 4 via dpp0 i n + 1 : ;must not be an instruction using dpp0 i n + 2 :mov dpp0:0000h,r1;move contents of r1 to address location ;010000 h (in data page 4) supposed segment. ;is enabled
c167cs derivatives the central processing unit (cpu) users manual 4-7 v2.0, 2000-07 explicit stack pointer updating none of the ret, reti, rets, retp or pop instructions is capable of correctly using a new sp register value, which is to be updated by an immediately preceding instruction. thus, in order to use the new sp register value without erroneously performed stack accesses, at least one instruction must be inserted between an explicitly sp-writing and any subsequent of the just mentioned implicitly sp-using instructions, as shown in the following example: i n :mov sp,#0fa40h ;select a new top of stack i n + 1 : ;must not be an instruction popping operands ;from the system stack i n + 2 :pop r0 ;pop word value from new top of stack ;into r0 note: conflicts with instructions writing to the stack (push, call, scxt) are solved internally by the cpu logic. controlling interrupts software modifications (implicit or explicit) of the psw are done in the execute phase of the respective instructions. in order to maintain fast interrupt responses, however, the current interrupt prioritization round does not consider these changes, i.e. an interrupt request may be acknowledged after the instruction that disables interrupts via ien or ilvl or after the following instructions. timecritical instruction sequences therefore should not begin directly after the instruction disabling interrupts, as shown in the following examples: interrupts_off: bclr ien ;globally disable interrupts ;non-critical instruction ;begin of uninterruptable critical sequence ;end of uninterruptable critical sequence interrupts_on: bset ien ;globally re-enable interrupts critical_sequence: atomic #3 ;immediately block interrupts bclr ien ;globally disable interrupts ;here is the uninterruptable sequence bset ien ;globally re-enable interrupts note: the described delay of 1 instruction also applies for enabling the interrupts system i.e. no interrupt requests are acknowledged until the instruction following the enabling instruction.
c167cs derivatives the central processing unit (cpu) users manual 4-8 v2.0, 2000-07 external memory access sequences the effect described here will only become noticeable, when watching the external memory access sequences on the external bus (e.g. by means of a logic analyzer). different pipeline stages can simultaneously put a request on the external bus controller (ebc). the sequence of instructions processed by the cpu may diverge from the sequence of the corresponding external memory accesses performed by the ebc, due to the predefined priority of external memory accesses: 1 st write data 2 nd fetch code 3 rd read data. initialization of port pins modifications of the direction of port pins (input or output) become effective only after the instruction following the modifying instruction. as bit instructions (bset, bclr) use internal read-modify-write sequences accessing the whole port, instructions modifying the port direction should be followed by an instruction that does not access the same port (see example below). port_init_wrong: bset dp3.13 ;change direction of p3.13 to output bset p3.9 ;p3.13 is still input, ;rd-mod-wr reads pin p3.13 port_init_right: bset dp3.13 ;change direction of p3.13 to output nop ;any instruction not accessing port 3 bset p3.9 ;p3.13 is now output, ;rd-mod-wr reads p3.13s output latch note: special attention must be paid to interrupt service routines that modify the same port as the software they have interrupted. changing the system configuration the instruction following an instruction that changes the system configuration via register syscon (e.g. the mapping of the internal rom, segmentation, stack size) cannot use the new resources (e.g. rom or stack). in these cases an instruction that does not access these resources should be inserted. code accesses to the new rom area are only possible after an absolute branch to this area. note: as a rule, instructions that change rom mapping should be executed from internal ram or external memory.
c167cs derivatives the central processing unit (cpu) users manual 4-9 v2.0, 2000-07 buscon/addrsel the instruction following an instruction that changes the properties of an external address area cannot access operands within the new area. in these cases an instruction that does not access this address area should be inserted. code accesses to the new address area should be made after an absolute branch to this area. note: as a rule, instructions that change external bus properties should not be executed from the respective external memory area. timing instruction pipelining reduces the average instruction processing time in a wide scale (from four to one machine cycles, mostly). however, there are some rare cases, where a particular pipeline situation causes the processing time for a single instruction to be extended either by a half or by one machine cycle. although this additional time represents only a tiny part of the total program execution time, it might be of interest to avoid these pipeline-caused time delays in time critical program modules. besides a general execution time description, section 4.3 provides some hints on how to optimize time-critical program parts with regard to such pipeline-caused timing particularities.
c167cs derivatives the central processing unit (cpu) users manual 4-10 v2.0, 2000-07 4.3 bit-handling and bit-protection the c167cs provides several mechanisms to manipulate bits. these mechanisms either manipulate software flags within the internal ram, control on-chip peripherals via control bits in their respective sfrs or control io functions via port pins. the instructions bset, bclr, band, bor, bxor, bmov, bmovn explicitly set or clear specific bits. the instructions bfldl and bfldh allow to manipulate up to 8 bits of a specific byte at one time. the instructions jbc and jnbs implicitly clear or set the specified bit when the jump is taken. the instructions jb and jnb (also conditional jump instructions that refer to flags) evaluate the specified bit to determine if the jump is to be taken. note: bit operations on undefined bit locations will always read a bit value of 0, while the write access will not effect the respective bit location. all instructions that manipulate single bits or bit groups internally use a read-modify-write sequence that accesses the whole word, which contains the specified bit(s). this method has several consequences: ? bits can only be modified within the internal address areas, i.e. internal ram and sfrs. external locations cannot be used with bit instructions. the upper 256 bytes of the sfr area, the esfr area and the internal ram are bit- addressable (see chapter 3 ), i.e. those register bits located within the respective sections can be directly manipulated using bit instructions. the other sfrs must be accessed byte/word wise. note: all gprs are bit-addressable independent of the allocation of the register bank via the context pointer cp. even gprs which are allocated to not bit-addressable ram locations provide this feature. ? the read-modify-write approach may be critical with hardware-effected bits. in these cases the hardware may change specific bits while the read-modify-write operation is in progress, where the writeback would overwrite the new bit value generated by the hardware. the solution is either the implemented hardware protection (see below) or realized through special programming (see chapter 4.2 ). protected bits are not changed during the read-modify-write sequence, i.e. when hardware sets e.g. an interrupt request flag between the read and the write of the read- modify-write sequence. the hardware protection logic guarantees that only the intended bit(s) is/are effected by the write-back operation. note: if a conflict occurs between a bit manipulation generated by hardware and an intended software access the software access has priority and determines the final value of the respective bit. a summary of the protected bits implemented in the c167cs can be found at the end of chapter 2 .
c167cs derivatives the central processing unit (cpu) users manual 4-11 v2.0, 2000-07 4.4 instruction state times basically, the time to execute an instruction depends on where the instruction is fetched from, and where possible operands are read from or written to. the fastest processing mode of the c167cs is to execute a program fetched from the internal code memory. in that case most of the instructions can be processed within just one machine cycle, which is also the general minimum execution time. all external memory accesses are performed by the c167css on-chip external bus controller (ebc), which works in parallel with the cpu. this section summarizes the execution times in a very condensed way. a detailed description of the execution times for the various instructions and the specific exceptions can be found in the c166 family instruction set manual . table 4-1 shows the minimum execution times required to process a c167cs instruction fetched from the internal code memory, the internal ram or from external memory. these execution times apply to most of the c167cs instructions - except some of the branches, the multiplication, the division and a special move instruction. in case of internal rom program execution there is no execution time dependency on the instruction length except for some special branch situations. the numbers in the table are in units of cpu clock cycles and assume no waitstates. execution from the internal ram provides flexibility in terms of loadable and modifyable code on the account of execution time. execution from external memory strongly depends on the selected bus mode and the programming of the bus cycles (waitstates). table 4-1 minimum execution times instruction fetch word operand access memory area word instruction doubleword instruction read from write to internal code memory 2 2 2 C internal ram 6 8 0/1 0 16-bit demux bus 2 4 2 2 16-bit mux bus 3 6 3 3 8-bit demux bus 4 8 4 4 8-bit mux bus 6 12 6 6
c167cs derivatives the central processing unit (cpu) users manual 4-12 v2.0, 2000-07 the operand and instruction accesses listed below can extend the execution time of an instruction: ? internal code memory operand reads (same for byte and word operand reads) ? internal ram operand reads via indirect addressing modes ? internal sfr operand reads immediately after writing ? external operand reads ? external operand writes ? jumps to non-aligned double word instructions in the internal rom space ? testing branch conditions immediately after psw writes 4.5 cpu special function registers the core cpu requires a set of special function registers (sfrs) to maintain the system state information, to supply the alu with register-addressable constants and to control system and bus configuration, multiply and divide alu operations, code memory segmentation, data memory paging, and accesses to the general purpose registers and the system stack. the access mechanism for these sfrs in the cpu core is identical to the access mechanism for any other sfr. since all sfrs can simply be controlled by means of any instruction, which is capable of addressing the sfr memory space, a lot of flexibility has been gained, without the need to create a set of system-specific instructions. note, however, that there are user access restrictions for some of the cpu core sfrs to ensure proper processor operations. the instruction pointer ip and code segment pointer csp cannot be accessed directly at all. they can only be changed indirectly via branch instructions. the psw, sp, and mdc registers can be modified not only explicitly by the programmer, but also implicitly by the cpu during normal instruction processing. note that any explicit write request (via software) to an sfr supersedes a simultaneous modification by hardware of the same register. note: any write operation to a single byte of an sfr clears the non-addressed complementary byte within the specified sfr. non-implemented (reserved) sfr bits cannot be modified, and will always supply a read value of 0.
c167cs derivatives the central processing unit (cpu) users manual 4-13 v2.0, 2000-07 the system configuration register syscon this bit-addressable register provides general system configuration and control functions. the reset value for register syscon depends on the state of the port0 pins during reset (see hardware effectable bits). . syscon system control register sfr (ff12 h /89 h ) reset value: 0xx0 h 151413121110987654321 0 stksz rom s1 sgt dis rom en byt dis clk en wr cfg cs cfg - ow d dis bd rst en xp en visi ble xper- share rw rw rw rwh rwh rw rwh rw - rwh rw rw rw rw bit function xper-share xbus peripheral share mode control 0: external accesses to xbus peripherals are disabled. 1: xbus peripherals are accessible via the external bus during hold mode. visible visible mode control 0: accesses to xbus peripherals are done internally. 1: xbus peripheral accesses are made visible on the external pins. xpen xbus peripheral enable bit 0: accesses to the on-chip x-peripherals and their functions are disabled. 1: the on-chip x-peripherals are enabled and can be accessed. bdrsten bidirectional reset enable bit 0: pin rstin is an input only. 1: pin rstin is pulled low during the internal reset sequence after any reset. owddis oscillator watchdog disable bit (depending on reset configuration) 0: the on-chip oscillator watchdog is enabled and active. 1: the on-chip oscillator watchdog is disabled and the cpu clock is always fed from the oscillator input. cscfg chip select configuration control (cleared after reset) 0: latched cs mode. the cs signals are latched internally and driven to the (enabled) port pins synchronously. 1: unlatched cs mode. the cs signals are directly derived from the address and driven to the (enabled) port pins. wrcfg write configuration control (set according to pin p0h.0 during reset) 0: pins wr and bhe retain their normal function. 1: pin wr acts as wrl , pin bhe acts as wrh .
c167cs derivatives the central processing unit (cpu) users manual 4-14 v2.0, 2000-07 note: register syscon cannot be changed after execution of the einit instruction. the function of bits xper-share, visible, wrcfg, bytdis, romen and roms1 is described in more detail in chapter 9 . clken system clock output enable (clkout, cleared after reset) 0: clkout disabled: pin may be used for general purpose io. 1: clkout enabled: pin outputs the system clock signal. bytdis disable/enable control for pin bhe (set according to data bus width) 0: pin bhe enabled. 1: pin bhe disabled, pin may be used for general purpose io. romen internal rom enable (set according to pin ea during reset) 0: internal program memory disabled, accesses to the rom area use the external bus. 1: internal program memory enabled. sgtdis segmentation disable/enable control (cleared after reset) 0: segmentation enabled. (csp is saved/restored during interrupt entry/exit) 1: segmentation disabled (only ip is saved/restored). roms1 internal rom mapping 0: internal rom area mapped to segment 0 (000000 h 007fff h ). 1: internal rom area mapped to segment 1 (010000 h 017fff h ). stksz system stack size selects the size of the system stack (in the internal ram) from 32 to 512 words. bit function
c167cs derivatives the central processing unit (cpu) users manual 4-15 v2.0, 2000-07 system clock output enable (clken) the system clock output function is enabled by setting bit clken in register syscon to 1. if enabled, port pin p3.15 takes on its alternate function as clkout output pin. the clock output is a 50% duty cycle clock (except for direct drive operation where clkout reflects the clock input signal, and for slowdown operation where clkout mirrors the cpu clock signal) whose frequency equals the cpu operating frequency ( f out = f cpu ). note: the output driver of port pin p3.15 is switched on automatically, when the clkout function is enabled. the port direction bit is disregarded. after reset, the clock output function is disabled (clken = 0). in emulation mode the clkout function is enabled automatically. while signal clkout is tightly coupled to the cpu clock signal, the programmable frequency signal fout (controlled by register focon) may be output on this pin. please refer to chapter 21 . segmentation disable/enable control (sgtdis) bit sgtdis allows to select either the segmented or non-segmented memory mode. in non-segmented memory mode (sgtdis = 1) it is assumed that the code address space is restricted to 64 kbytes (segment 0) and thus 16 bits are sufficient to represent all code addresses. for implicit stack operations (call or ret) the csp register is totally ignored and only the ip is saved to and restored from the stack. in segmented memory mode (sgtdis = 0) it is assumed that the whole address space is available for instructions. for implicit stack operations (call or ret) the csp register and the ip are saved to and restored from the stack. after reset the segmented memory mode is selected. note: bit sgtdis controls if the csp register is pushed onto the system stack in addition to the ip register before an interrupt service routine is entered, and it is repopped when the interrupt service routine is left again. system stack size (stksz) this bitfield defines the size of the physical system stack, which is located in the internal ram of the c167cs. an area of 32 512 words or all of the internal ram may be dedicated to the system stack. a so-called circular stack mechanism allows to use a bigger virtual stack than this dedicated ram area. these techniques as well as the encoding of bitfield stksz are described in more detail in chapter 22 .
c167cs derivatives the central processing unit (cpu) users manual 4-16 v2.0, 2000-07 the processor status word psw this bit-addressable register reflects the current state of the microcontroller. two groups of bits represent the current alu status, and the current cpu interrupt status. a separate bit (usr0) within register psw is provided as a general purpose user flag. alu status (n, c, v, z, e, mulip) the condition flags (n, c, v, z, e) within the psw indicate the alu status due to the last recently performed alu operation. they are set by most of the instructions due to specific rules, which depend on the alu or data movement operation performed by an instruction. psw program status word sfr (ff10 h /88 h ) reset value: 0000 h 1514131211109876543210 ilvl ien hld en ---usr0 mul ip ezvcn rwh rw rw - - - rw rwh rwh rwh rwh rwh rwh bit function n negative result set, when the result of an alu operation is negative. c carry flag set, when the result of an alu operation produces a carry bit. v overflow result set, when the result of an alu operation produces an overflow. zzero flag set, when the result of an alu operation is zero. e end of table flag set, when the source operand of an instruction is 8000 h or 80 h . mulip multiplication/division in progress 0: there is no multiplication/division in progress. 1: a multiplication/division has been interrupted. usr0 user general purpose flag may be used by the application software. hlden, ilvl, ien interrupt and ebc control fields define the response to interrupt requests and enable external bus arbitration. (described in chapter 5 )
c167cs derivatives the central processing unit (cpu) users manual 4-17 v2.0, 2000-07 after execution of an instruction which explicitly updates the psw register, the condition flags cannot be interpreted as described in the following, because any explicit write to the psw register supersedes the condition flag values, which are implicitly generated by the cpu. explicitly reading the psw register supplies a read value which represents the state of the psw register after execution of the immediately preceding instruction. note: after reset, all of the alu status bits are cleared. n-flag: for most of the alu operations, the n-flag is set to 1, if the most significant bit of the result contains a 1, otherwise it is cleared. in the case of integer operations the n-flag can be interpreted as the sign bit of the result (negative: n = 1, positive: n = 0). negative numbers are always represented as the 2s complement of the corresponding positive number. the range of signed numbers extends from C 8000 h to + 7fff h for the word data type, or from C 80 h to + 7f h for the byte data type. for boolean bit operations with only one operand the n-flag represents the previous state of the specified bit. for boolean bit operations with two operands the n-flag represents the logical xoring of the two specified bits. c-flag: after an addition the c-flag indicates that a carry from the most significant bit of the specified word or byte data type has been generated. after a subtraction or a comparison the c-flag indicates a borrow, which represents the logical negation of a carry for the addition. this means that the c-flag is set to 1, if no carry from the most significant bit of the specified word or byte data type has been generated during a subtraction, which is performed internally by the alu as a 2s complement addition, and the c-flag is cleared when this complement addition caused a carry. the c-flag is always cleared for logical, multiply and divide alu operations, because these operations cannot cause a carry anyhow. for shift and rotate operations the c-flag represents the value of the bit shifted out last. if a shift count of zero is specified, the c-flag will be cleared. the c-flag is also cleared for a prioritize alu operation, because a 1 is never shifted out of the msb during the normalization of an operand. for boolean bit operations with only one operand the c-flag is always cleared. for boolean bit operations with two operands the c-flag represents the logical anding of the two specified bits. v-flag: for addition, subtraction and 2s complementation the v-flag is always set to 1, if the result overflows the maximum range of signed numbers, which are representable by either 16 bits for word operations (C 8000 h to + 7fff h ), or by 8 bits for byte operations (C 80 h to + 7f h ), otherwise the v-flag is cleared. note that the result of an integer addition, integer subtraction, or 2s complement is not valid, if the v-flag indicates an arithmetic overflow. for multiplication and division the v-flag is set to 1, if the result cannot be represented in a word data type, otherwise it is cleared. note that a division by zero will always cause an overflow. in contrast to the result of a division, the result of a multiplication is valid
c167cs derivatives the central processing unit (cpu) users manual 4-18 v2.0, 2000-07 regardless of whether the v-flag is set to 1 or not. since logical alu operations cannot produce an invalid result, the v-flag is cleared by these operations. the v-flag is also used as sticky bit for rotate right and shift right operations. with only using the c-flag, a rounding error caused by a shift right operation can be estimated up to a quantity of one half of the lsb of the result. in conjunction with the v-flag, the c-flag allows evaluating the rounding error with a finer resolution (see table 4-2 ). for boolean bit operations with only one operand the v-flag is always cleared. for boolean bit operations with two operands the v-flag represents the logical oring of the two specified bits. z-flag: the z-flag is normally set to 1, if the result of an alu operation equals zero, otherwise it is cleared. for the addition and subtraction with carry the z-flag is only set to 1, if the z-flag already contains a 1 and the result of the current alu operation additionally equals zero. this mechanism is provided for the support of multiple precision calculations. for boolean bit operations with only one operand the z-flag represents the logical negation of the previous state of the specified bit. for boolean bit operations with two operands the z-flag represents the logical noring of the two specified bits. for the prioritize alu operation the z-flag indicates, if the second operand was zero or not. e-flag: the e-flag can be altered by instructions, which perform alu or data movement operations. the e-flag is cleared by those instructions which cannot be reasonably used for table search operations. in all other cases the e-flag is set depending on the value of the source operand to signify whether the end of a search table is reached or not. if the value of the source operand of an instruction equals the lowest negative number, which is representable by the data format of the corresponding instruction (8000 h for the word data type, or 80 h for the byte data type), the e-flag is set to 1, otherwise it is cleared. mulip-flag: the mulip-flag will be set to 1 by hardware upon the entrance into an interrupt service routine, when a multiply or divide alu operation was interrupted before completion. depending on the state of the mulip bit, the hardware decides whether a multiplication or division must be continued or not after the end of an interrupt service. the mulip bit is overwritten with the contents of the stacked mulip-flag when the return-from-interrupt-instruction (reti) is executed. this normally means that the mulip-flag is cleared again after that. table 4-2 shift right rounding error evaluation c-flag v-flag rounding error quantity 0 0 1 1 0 1 0 1 C no rounding error C 0 < rounding error < 1 / 2 lsb rounding error = 1 / 2 lsb rounding error > 1 / 2 lsb
c167cs derivatives the central processing unit (cpu) users manual 4-19 v2.0, 2000-07 note: the mulip flag is a part of the task environment! when the interrupting service routine does not return to the interrupted multiply/divide instruction ( i.e. in case of a task scheduler that switches between independent tasks), the mulip flag must be saved as part of the task environment and must be updated accordingly for the new task before this task is entered. cpu interrupt status (ien, ilvl) the interrupt enable bit allows to globally enable (ien = 1) or disable (ien = 0) interrupts. the four-bit interrupt level field (ilvl) specifies the priority of the current cpu activity. the interrupt level is updated by hardware upon entry into an interrupt service routine, but it can also be modified via software to prevent other interrupts from being acknowledged. in case an interrupt level 15 has been assigned to the cpu, it has the highest possible priority, and thus the current cpu operation cannot be interrupted except by hardware traps or external non-maskable interrupts. for details please refer to chapter 5 . after reset all interrupts are globally disabled, and the lowest priority (ilvl = 0) is assigned to the initial cpu activity. the instruction pointer ip this register determines the 16-bit intra-segment address of the currently fetched instruction within the code segment selected by the csp register. the ip register is not mapped into the c167css address space, and thus it is not directly accessible by the programmer. the ip can, however, be modified indirectly via the stack by means of a return instruction. the ip register is implicitly updated by the cpu for branch instructions and after instruction fetch operations. ip instruction pointer - - - (- - - -/- -) reset value: 0000 h 1514131211109876543210 ip (r)(w)h bit function ip specifies the intra segment offset, from where the current instruction is to be fetched. ip refers to the current segment .
c167cs derivatives the central processing unit (cpu) users manual 4-20 v2.0, 2000-07 the code segment pointer csp this non-bit addressable register selects the code segment being used at run-time to access instructions. the lower 8 bits of register csp select one of up to 256 segments of 64 kbytes each, while the upper 8 bits are reserved for future use. code memory addresses are generated by directly extending the 16-bit contents of the ip register by the contents of the csp register as shown in figure 4-5 . in case of the segmented memory mode the selected number of segment address bits (via bitfield salsel) of register csp is output on the respective segment address pins of port 4 for all external code accesses. for non-segmented memory mode or single chip mode the content of this register is not significant, because all code accesses are automatically restricted to segment 0. note: the csp register can only be read but not written by data operations. it is, however, modified either directly by means of the jmps and calls instructions, or indirectly via the stack by means of the rets and reti instructions. upon the acceptance of an interrupt or the execution of a software trap instruction, the csp register is automatically set to zero. csp code segment pointer sfr (fe08 h /04 h ) reset value: 0000 h 1514131211109876543210 -------- segnr - - - - - - - - r(w)h bit function segnr segment number specifies the code segment, from where the current instruction is to be fetched. segnr is ignored, when segmentation is disabled.
c167cs derivatives the central processing unit (cpu) users manual 4-21 v2.0, 2000-07 figure 4-5 addressing via the code segment pointer note: when segmentation is disabled, the ip value is used directly as the 16-bit address. mca02265 255 1 15 0 ip register 254 0 code segment ff'ffff h fe'0000 h 01'0000 h 00'0000 h csp register 15 0 24/20/18-bit physical code address
c167cs derivatives the central processing unit (cpu) users manual 4-22 v2.0, 2000-07 the data page pointers dpp0, dpp1, dpp2, dpp3 these four non-bit addressable registers select up to four different data pages being active simultaneously at run-time. the lower 10 bits of each dpp register select one of the 1024 possible 16-kbyte data pages while the upper 6 bits are reserved for future use. the dpp registers allow to access the entire memory space in pages of 16 kbytes each. dpp0 data page pointer 0 sfr (fe00 h /00 h ) reset value: 0000 h 1514131211109876543210 ------ dpp0pn - - - - - - rw dpp1 data page pointer 1 sfr (fe02 h /01 h ) reset value: 0001 h 1514131211109876543210 ------ dpp1pn - - - - - - rw dpp2 data page pointer 2 sfr (fe04 h /02 h ) reset value: 0002 h 1514131211109876543210 ------ dpp2pn - - - - - - rw dpp3 data page pointer 3 sfr (fe06 h /03 h ) reset value: 0003 h 1514131211109876543210 ------ dpp3pn - - - - - - rw
c167cs derivatives the central processing unit (cpu) users manual 4-23 v2.0, 2000-07 the dpp registers are implicitly used, whenever data accesses to any memory location are made via indirect or direct long 16-bit addressing modes (except for override accesses via extended instructions and pec data transfers). after reset, the data page pointers are initialized in a way that all indirect or direct long 16-bit addresses result in identical 18-bit addresses. this allows to access data pages 3 0 within segment 0 as shown in figure 4-6 . if the user does not want to use any data paging, no further action is required. data paging is performed by concatenating the lower 14 bits of an indirect or direct long 16-bit address with the contents of the dpp register selected by the upper two bits of the 16-bit address. the contents of the selected dpp register specify one of the 1024 possible data pages. this data page base address together with the 14-bit page offset forms the physical 24-bit address (selectable part is driven to the address pins). in case of non-segmented memory mode, only the two least significant bits of the implicitly selected dpp register are used to generate the physical address. thus, extreme care should be taken when changing the content of a dpp register, if a non- segmented memory model is selected, because otherwise unexpected results could occur. in case of the segmented memory mode the selected number of segment address bits (via bitfield salsel) of the respective dpp register is output on the respective segment address pins of port 4 for all external data accesses. a dpp register can be updated via any instruction, which is capable of modifying an sfr. note: due to the internal instruction pipeline, a new dpp value is not yet usable for the operand address calculation of the instruction immediately following the instruction updating the dpp register. bit function dppxpn data page number of dppx specifies the data page selected via dppx. only the least significant two bits of dppx are significant, when segmentation is disabled.
c167cs derivatives the central processing unit (cpu) users manual 4-24 v2.0, 2000-07 figure 4-6 addressing via the data page pointers mca02264 1023 1022 1021 3 2 1 0 dpp registers dpp3-11 dpp2-10 dpp1-01 dpp0-00 15 14 0 16-bit data address 14-bit intra-page address (concatenated with content of dppx). affer reset or with segmentation disabled the dpp registers select data pages 3...0. all of the internal memory is accessible in these cases.
c167cs derivatives the central processing unit (cpu) users manual 4-25 v2.0, 2000-07 the context pointer cp this non-bit addressable register is used to select the current register context. this means that the cp register value determines the address of the first general purpose register (gpr) within the current register bank of up to 16 wordwide and/or bytewide gprs. note: it is the users responsibility that the physical gpr address specified via cp register plus short gpr address must always be an internal ram location. if this condition is not met, unexpected results may occur. ? do not set cp below the iram start address, i.e. 00fa00 h /00f600 h /00f200 h (referring to an iram size of 1/2/3 kbyte) ? do not set cp above 00fdfe h ? be careful using the upper gprs with cp above 00fde0 h the cp register can be updated via any instruction which is capable of modifying an sfr. note: due to the internal instruction pipeline, a new cp value is not yet usable for gpr address calculations of the instruction immediately following the instruction updating the cp register. the switch context instruction (scxt) allows to save the content of register cp on the stack and updating it with a new value in just one machine cycle. cp context pointer sfr (fe10 h /08 h ) reset value: fc00 h 1514131211109876543210 1111 cp 0 r r r r rw r bit function cp modifiable portion of register cp specifies the (word) base address of the current register bank. when writing a value to register cp with bits cp.11 cp.9 = 000, bits cp.11 cp.10 are set to 11 by hardware, in all other cases all bits of bit field cp receive the written value.
c167cs derivatives the central processing unit (cpu) users manual 4-26 v2.0, 2000-07 figure 4-7 register bank selection via register cp several addressing modes use register cp implicitly for address calculations. the addressing modes mentioned below are described in chapter 24 . short 4-bit gpr addresses (mnemonic: rw or rb) specify an address relative to the memory location specified by the contents of the cp register, i.e. the base of the current register bank. depending on whether a relative word (rw) or byte (rb) gpr address is specified, the short 4-bit gpr address is either multiplied by two or not before it is added to the content of register cp (see figure 4-8 ). thus, both byte and word gpr accesses are possible in this way. gprs used as indirect address pointers are always accessed wordwise. for some instructions only the first four gprs can be used as indirect address pointers. these gprs are specified via short 2-bit gpr addresses. the respective physical address calculation is identical to that for the short 4-bit gpr addresses. short 8-bit register addresses (mnemonic: reg or bitoff) within a range from f0 h to ff h interpret the four least significant bits as short 4-bit gpr address, while the four most significant bits are ignored. the respective physical gpr address calculation is identical to that for the short 4-bit gpr addresses. for single bit accesses on a gpr, the gprs word address is calculated as just described, but the position of the bit within the word is specified by a separate additional 4-bit value. mcd02003 r0 r1 r2 r3 r4 r5 r6 r7 r8 r9 r10 r11 r12 r13 r14 r15 context pointer (cp) + 30 (cp) + 28 (cp) + 2 (cp) internal ram . . .
c167cs derivatives the central processing unit (cpu) users manual 4-27 v2.0, 2000-07 figure 4-8 implicit cp use by short gpr addressing modes the stack pointer sp this non-bit addressable register is used to point to the top of the internal system stack (tos). the sp register is pre-decremented whenever data is to be pushed onto the stack, and it is post-incremented whenever data is to be popped from the stack. thus, the system stack grows from higher toward lower memory locations. since the least significant bit of register sp is tied to 0 and bits 15 through 12 are tied to 1 by hardware, the sp register can only contain values from f000 h to fffe h . this allows to access a physical stack within the internal ram of the c167cs. a virtual stack (usually bigger) can be realized via software. this mechanism is supported by registers stkov and stkun (see respective descriptions below). the sp register can be updated via any instruction, which is capable of modifying an sfr. note: due to the internal instruction pipeline, a pop or return instruction must not immediately follow an instruction updating the sp register. sp stack pointer register sfr (fe12 h /09 h ) reset value: fc00 h 1514131211109876543210 1111 sp 0 r r r r rwh r bit function sp modifiable portion of register sp specifies the top of the internal system stack. for word gpr accesses accesses for byte gpr control 1111 specified by reg or bitoff context pointer + 4-bit gpr address 2 * mcd02005 internal gprs ram must be within the ram area internal
c167cs derivatives the central processing unit (cpu) users manual 4-28 v2.0, 2000-07 the stack overflow pointer stkov this non-bit addressable register is compared against the sp register after each operation, which pushes data onto the system stack (e.g. push and call instructions or interrupts) and after each subtraction from the sp register. if the content of the sp register is less than the content of the stkov register, a stack overflow hardware trap will occur. since the least significant bit of register stkov is tied to 0 and bits 15 through 12 are tied to 1 by hardware, the stkov register can only contain values from f000 h to fffe h . the stack overflow trap (entered when (sp) < (stkov)) may be used in two different ways: ? fatal error indication treats the stack overflow as a system error through the associated trap service routine. under these circumstances data in the bottom of the stack may have been overwritten by the status information stacked upon servicing the stack overflow trap. ? automatic system stack flushing allows to use the system stack as a stack cache for a bigger external user stack. in this case register stkov should be initialized to a value, which represents the desired lowest top of stack address plus 12 according to the selected maximum stack size. this considers the worst case that will occur, when a stack overflow condition is detected just during entry into an interrupt service routine. then, six additional stack word locations are required to push ip, psw, and csp for both the interrupt service routine and the hardware trap service routine. more details about the stack overflow trap service routine and virtual stack management are given in chapter 22 . stkov stack overflow reg. sfr (fe14 h /0a h ) reset value: fa00 h 1514131211109876543210 1111 stkov 0 r r r r rw r bit function stkov modifiable portion of register stkov specifies the lower limit of the internal system stack.
c167cs derivatives the central processing unit (cpu) users manual 4-29 v2.0, 2000-07 the stack underflow pointer stkun this non-bit addressable register is compared against the sp register after each operation, which pops data from the system stack (e.g. pop and ret instructions) and after each addition to the sp register. if the content of the sp register is greater than the content of the stkun register, a stack underflow hardware trap will occur. since the least significant bit of register stkun is tied to 0 and bits 15 through 12 are tied to 1 by hardware, the stkun register can only contain values from f000 h to fffe h . the stack underflow trap (entered when (sp) > (stkun)) may be used in two different ways: ? fatal error indication treats the stack underflow as a system error through the associated trap service routine. ? automatic system stack refilling allows to use the system stack as a stack cache for a bigger external user stack. in this case register stkun should be initialized to a value, which represents the desired highest bottom of stack address. more details about the stack underflow trap service routine and virtual stack management are given in chapter 22 . scope of stack limit control the stack limit control realized by the register pair stkov and stkun detects cases where the stack pointer sp is moved outside the defined stack area either by add or sub instructions or by push or pop operations (explicit or implicit, i.e. call or ret instructions). this control mechanism is not triggered, i.e. no stack trap is generated, when ? the stack pointer sp is directly updated via mov instructions ? the limits of the stack area (stkov, stkun) are changed, so that sp is outside of the new limits. stkun stack underflow reg. sfr (fe16 h /0b h ) reset value: fc00 h 1514131211109876543210 1111 stkun 0 r r r r rw r bit function stkun modifiable portion of register stkun specifies the upper limit of the internal system stack.
c167cs derivatives the central processing unit (cpu) users manual 4-30 v2.0, 2000-07 the multiply/divide high register mdh this register is a part of the 32-bit multiply/divide register, which is implicitly used by the cpu, when it performs a multiplication or a division. after a multiplication, this non-bit addressable register represents the high order 16 bits of the 32-bit result. for long divisions, the mdh register must be loaded with the high order 16 bits of the 32-bit dividend before the division is started. after any division, register mdh represents the 16-bit remainder. whenever this register is updated via software, the multiply/divide register in use (mdriu) flag in the multiply/divide control register (mdc) is set to 1. when a multiplication or division is interrupted before its completion and when a new multiply or divide operation is to be performed within the interrupt service routine, register mdh must be saved along with registers mdl and mdc to avoid erroneous results. a detailed description of how to use the mdh register for programming multiply and divide algorithms can be found in chapter 22 . mdh multiply/divide high reg. sfr (fe0c h /06 h ) reset value: 0000 h 1514131211109876543210 mdh rwh bit function mdh specifies the high order 16 bits of the 32-bit multiply and divide reg. md.
c167cs derivatives the central processing unit (cpu) users manual 4-31 v2.0, 2000-07 the multiply/divide low register mdl this register is a part of the 32-bit multiply/divide register, which is implicitly used by the cpu, when it performs a multiplication or a division. after a multiplication, this non-bit addressable register represents the low order 16 bits of the 32-bit result. for long divisions, the mdl register must be loaded with the low order 16 bits of the 32-bit dividend before the division is started. after any division, register mdl represents the 16-bit quotient. whenever this register is updated via software, the multiply/divide register in use (mdriu) flag in the multiply/divide control register (mdc) is set to 1. the mdriu flag is cleared, whenever the mdl register is read via software. when a multiplication or division is interrupted before its completion and when a new multiply or divide operation is to be performed within the interrupt service routine, register mdl must be saved along with registers mdh and mdc to avoid erroneous results. a detailed description of how to use the mdl register for programming multiply and divide algorithms can be found in chapter 22 . mdl multiply/divide low reg. sfr (fe0e h /07 h ) reset value: 0000 h 1514131211109876543210 mdl rwh bit function mdl specifies the low order 16 bits of the 32-bit multiply and divide reg. md.
c167cs derivatives the central processing unit (cpu) users manual 4-32 v2.0, 2000-07 the multiply/divide control register mdc this bit addressable 16-bit register is implicitly used by the cpu, when it performs a multiplication or a division. it is used to store the required control information for the corresponding multiply or divide operation. register mdc is updated by hardware during each single cycle of a multiply or divide instruction. when a division or multiplication was interrupted before its completion and the multiply/ divide unit is required, the mdc register must first be saved along with registers mdh and mdl (to be able to restart the interrupted operation later), and then it must be cleared prepare it for the new calculation. after completion of the new division or multiplication, the state of the interrupted multiply or divide operation must be restored. the mdriu flag is the only portion of the mdc register which might be of interest for the user. the remaining portions of the mdc register are reserved for dedicated use by the hardware, and should never be modified by the user in another way than described above. otherwise, a correct continuation of an interrupted multiply or divide operation cannot be guaranteed. a detailed description of how to use the mdc register for programming multiply and divide algorithms can be found in chapter 22 . mdc multiply/divide control reg. sfr (ff0e h /87 h ) reset value: 0000 h 1514131211109876543210 --------! !! !! ! mdr iu ! !! !! !! ! - - - - - - - - r(w)h r(w)h r(w)h r(w)h r(w)h r(w)h r(w)h r(w)h bit function mdriu multiply/divide register in use 0: cleared, when register mdl is read via software. 1: set when register mdl or mdh is written via software, or when a multiply or divide instruction is executed. !! internal machine status the multiply/divide unit uses these bits to control internal operations. never modify these bits without saving and restoring register mdc.
c167cs derivatives the central processing unit (cpu) users manual 4-33 v2.0, 2000-07 the constant zeros register zeros all bits of this bit-addressable register are fixed to 0 by hardware. this register can be read only. register zeros can be used as a register-addressable constant of all zeros, i.e. for bit manipulation or mask generation. it can be accessed via any instruction, which is capable of addressing an sfr. the constant ones register ones all bits of this bit-addressable register are fixed to 1 by hardware. this register can be read only. register ones can be used as a register-addressable constant of all ones, i.e. for bit manipulation or mask generation. it can be accessed via any instruction, which is capable of addressing an sfr. zeros zeros register sfr (ff1c h /8e h ) reset value: 0000 h 1514131211109876543210 0000000000000000 r r r r r r r r r r r r r r r r ones ones register sfr (ff1e h /8f h ) reset value: ffff h 1514131211109876543210 1111111111111111 r r r r r r r r r r r r r r r r
c167cs derivatives interrupt and trap functions users manual 5-1 v2.0, 2000-07 5 interrupt and trap functions the architecture of the c167cs supports several mechanisms for fast and flexible response to service requests that can be generated from various sources internal or external to the microcontroller. these mechanisms include: normal interrupt processing the cpu temporarily suspends the current program execution and branches to an interrupt service routine in order to service an interrupt requesting device. the current program status (ip, psw, in segmentation mode also csp) is saved on the internal system stack. a prioritization scheme with 16 priority levels allows the user to specify the order in which multiple interrupt requests are to be handled. interrupt processing via the peripheral event controller (pec) a faster alternative to normal software controlled interrupt processing is servicing an interrupt requesting device with the c167cs s integrated peripheral event controller (pec). triggered by an interrupt request, the pec performs a single word or byte data transfer between any two locations in segment 0 (data pages 0 through 3) through one of eight programmable pec service channels. during a pec transfer the normal program execution of the cpu is halted for just 1 instruction cycle. no internal program status information needs to be saved. the same prioritization scheme is used for pec service as for normal interrupt processing. pec transfers share the 2 highest priority levels. trap functions trap functions are activated in response to special conditions that occur during the execution of instructions. a trap can also be caused externally by the non-maskable interrupt pin nmi . several hardware trap functions are provided for handling erroneous conditions and exceptions that arise during the execution of an instruction. hardware traps always have highest priority and cause immediate system reaction. the software trap function is invoked by the trap instruction, which generates a software interrupt for a specified interrupt vector. for all types of traps the current program status is saved on the system stack. external interrupt processing although the c167cs does not provide dedicated interrupt pins, it allows to connect external interrupt sources and provides several mechanisms to react on external events, including standard inputs, non-maskable interrupts and fast external interrupts. these interrupt functions are alternate port functions, except for the non-maskable interrupt and the reset input.
c167cs derivatives interrupt and trap functions users manual 5-2 v2.0, 2000-07 5.1 interrupt system structure the c167cs provides 56 separate interrupt nodes that may be assigned to 16 priority levels. in order to support modular and consistent software design techniques, most sources of an interrupt or pec request are supplied with a separate interrupt control register and interrupt vector. the control register contains the interrupt request flag, the interrupt enable bit, and the interrupt priority of the associated source. each source request is then activated by one specific event, depending on the selected operating mode of the respective device. for efficient usage of the resources also multi-source interrupt nodes are incorporated. these nodes can be activated by several source requests, e.g. as different kinds of errors in the serial interfaces. however, specific status flags which identify the type of error are implemented in the serial channels control registers. the c167cs provides a vectored interrupt system. in this system specific vector locations in the memory space are reserved for the reset, trap, and interrupt service functions. whenever a request occurs, the cpu branches to the location that is associated with the respective interrupt source. this allows direct identification of the source that caused the request. the only exceptions are the class b hardware traps, which all share the same interrupt vector. the status flags in the trap flag register (tfr) can then be used to determine which exception caused the trap. for the special software trap instruction, the vector address is specified by the operand field of the instruction, which is a seven bit trap number. the reserved vector locations build a jump table in the low end of the c167css address space (segment 0). the jump table is made up of the appropriate jump instructions that transfer control to the interrupt or trap service routines, which may be located anywhere within the address space. the entries of the jump table are located at the lowest addresses in code segment 0 of the address space. each entry occupies 2 words, except for the reset vector and the hardware trap vectors, which occupy 4 or 8 words. table 5-1 lists all sources that are capable of requesting interrupt or pec service in the c167cs, the associated interrupt vectors, their locations and the associated trap numbers. it also lists the mnemonics of the affected interrupt request flags and their corresponding interrupt enable flags. the mnemonics are composed of a part that specifies the respective source, followed by a part that specifies their function (ir = interrupt request flag, ie = interrupt enable flag). note: each entry of the interrupt vector table provides room for two word instructions or one doubleword instruction. the respective vector location results from multiplying the trap number by 4 (4 bytes per entry). all interrupt nodes that are currently not used by their associated modules or are not connected to a module in the actual derivative may be used to generate software controlled interrupt requests by setting the respective ir flag.
c167cs derivatives interrupt and trap functions users manual 5-3 v2.0, 2000-07 table 5-1 c167cs interrupt notes and vectors source of interrupt or pec service request request flag enable flag interrupt vector vector location trap number capcom register 0 cc0ir cc0ie cc0int 000040 h 10 h /16 d capcom register 1 cc1ir cc1ie cc1int 000044 h 11 h /17 d capcom register 2 cc2ir cc2ie cc2int 000048 h 12 h /18 d capcom register 3 cc3ir cc3ie cc3int 00004c h 13 h /19 d capcom register 4 cc4ir cc4ie cc4int 000050 h 14 h /20 d capcom register 5 cc5ir cc5ie cc5int 000054 h 15 h /21 d capcom register 6 cc6ir cc6ie cc6int 000058 h 16 h /22 d capcom register 7 cc7ir cc7ie cc7int 00005c h 17 h /23 d capcom register 8 cc8ir cc8ie cc8int 000060 h 18 h /24 d capcom register 9 cc9ir cc9ie cc9int 000064 h 19 h /25 d capcom register 10 cc10ir cc10ie cc10int 000068 h 1a h /26 d capcom register 11 cc11ir cc11ie cc11int 00006c h 1b h /27 d capcom register 12 cc12ir cc12ie cc12int 000070 h 1c h /28 d capcom register 13 cc13ir cc13ie cc13int 000074 h 1d h /29 d capcom register 14 cc14ir cc14ie cc14int 000078 h 1e h /30 d capcom register 15 cc15ir cc15ie cc15int 00007c h 1f h /31 d capcom register 16 cc16ir cc16ie cc16int 0000c0 h 30 h /48 d capcom register 17 cc17ir cc17ie cc17int 0000c4 h 31 h /49 d capcom register 18 cc18ir cc18ie cc18int 0000c8 h 32 h /50 d capcom register 19 cc19ir cc19ie cc19int 0000cc h 33 h /51 d capcom register 20 cc20ir cc20ie cc20int 0000d0 h 34 h /52 d capcom register 21 cc21ir cc21ie cc21int 0000d4 h 35 h /53 d capcom register 22 cc22ir cc22ie cc22int 0000d8 h 36 h /54 d capcom register 23 cc23ir cc23ie cc23int 0000dc h 37 h /55 d capcom register 24 cc24ir cc24ie cc24int 0000e0 h 38 h /56 d capcom register 25 cc25ir cc25ie cc25int 0000e4 h 39 h /57 d capcom register 26 cc26ir cc26ie cc26int 0000e8 h 3a h /58 d capcom register 27 cc27ir cc27ie cc27int 0000ec h 3b h /59 d capcom register 28 cc28ir cc28ie cc28int 0000f0 h 3c h /60 d capcom register 29 cc29ir cc29ie cc29int 000110 h 44 h /68 d
c167cs derivatives interrupt and trap functions users manual 5-4 v2.0, 2000-07 capcom register 30 cc30ir cc30ie cc30int 000114 h 45 h /69 d capcom register 31 cc31ir cc31ie cc31int 000118 h 46 h /70 d capcom timer 0 t0ir t0ie t0int 000080 h 20 h /32 d capcom timer 1 t1ir t1ie t1int 000084 h 21 h /33 d capcom timer 7 t7ir t7ie t7int 0000f4 h 3d h /61 d capcom timer 8 t8ir t8ie t8int 0000f8 h 3e h /62 d gpt1 timer 2 t2ir t2ie t2int 000088 h 22 h /34 d gpt1 timer 3 t3ir t3ie t3int 00008c h 23 h /35 d gpt1 timer 4 t4ir t4ie t4int 000090 h 24 h /36 d gpt2 timer 5 t5ir t5ie t5int 000094 h 25 h /37 d gpt2 timer 6 t6ir t6ie t6int 000098 h 26 h /38 d gpt2 caprel register crir crie crint 00009c h 27 h /39 d a/d conversion complete adcir adcie adcint 0000a0 h 28 h /40 d a/d overrun error adeir adeie adeint 0000a4 h 29 h /41 d asc0 transmit s0tir s0tie s0tint 0000a8 h 2a h /42 d asc0 transmit buffer s0tbir s0tbie s0tbint 00011c h 47 h /71 d asc0 receive s0rir s0rie s0rint 0000ac h 2b h /43 d asc0 error s0eir s0eie s0eint 0000b0 h 2c h /44 d ssc transmit sctir sctie sctint 0000b4 h 2d h /45 d ssc receive scrir scrie scrint 0000b8 h 2e h /46 d ssc error sceir sceie sceint 0000bc h 2f h /47 d pwm channel 0 3 pwmir pwmie pwmint 0000fc h 3f h /63 d can1 xp0ir xp0ie xp0int 000100 h 40 h /64 d can2 xp1ir xp1ie xp1int 000104 h 41 h /65 d unassigned node xp2ir xp2ie xp2int 000108 h 42 h /66 d pll/owd, rtc xp3ir xp3ie xp3int 00010c h 43 h /67 d table 5-1 c167cs interrupt notes and vectors (contd) source of interrupt or pec service request request flag enable flag interrupt vector vector location trap number
c167cs derivatives interrupt and trap functions users manual 5-5 v2.0, 2000-07 table 5-2 lists the vector locations for hardware traps and the corresponding status flags in register tfr. it also lists the priorities of trap service for cases, where more than one trap condition might be detected within the same instruction. after any reset (hardware reset, software reset instruction srst, or reset by watchdog timer overflow) program execution starts at the reset vector at location 000000 h . reset conditions have priority over every other system activity and therefore have the highest priority (trap priority iii). software traps may be initiated to any vector location between 000000 h and 0001fc h . a service routine entered via a software trap instruction is always executed on the current cpu priority level which is indicated in bit field ilvl in register psw. this means that routines entered via the software trap instruction can be interrupted by all hardware traps or higher level interrupt requests. table 5-2 hardware trap summary exception condition trap flag trap vector vector location trap number trap prio reset functions hardware reset software reset watchdog timer overflow C reset reset reset 000000 h 000000 h 000000 h 00 h 00 h 00 h iii iii iii class a hardware traps non-maskable interrupt stack overflow stack underflow nmi stkof stkuf nmitrap stotrap stutrap 000008 h 000010 h 000018 h 02 h 04 h 06 h ii ii ii class b hardware traps undefined opcode protected instruction fault illegal word operand access illegal instruction access illegal external bus access undopc prtflt illopa illina illbus btrap btrap btrap btrap btrap 000028 h 000028 h 000028 h 000028 h 000028 h 0a h 0a h 0a h 0a h 0a h i i i i i reserved C C [2c h -3c h ][0b h -0f h ] software traps trap instruction C C any [000000 h - 0001fc h ] in steps of 4 h any [00 h -7f h ] current cpu priority
c167cs derivatives interrupt and trap functions users manual 5-6 v2.0, 2000-07 normal interrupt processing and pec service during each instruction cycle one out of all sources which require pec or interrupt processing is selected according to its interrupt priority. this priority of interrupts and pec requests is programmable in two levels. each requesting source can be assigned to a specific priority. a second level (called group priority) allows to specify an internal order for simultaneous requests from a group of different sources on the same priority level. at the end of each instruction cycle the one source request with the highest current priority will be determined by the interrupt system. this request will then be serviced, if its priority is higher than the current cpu priority in register psw. interrupt system register description interrupt processing is controlled globally by register psw through a general interrupt enable bit (ien) and the cpu priority field (ilvl). additionally the different interrupt sources are controlled individually by their specific interrupt control registers ( ic). thus, the acceptance of requests by the cpu is determined by both the individual interrupt control registers and the psw. pec services are controlled by the respective peccx register and the source and destination pointers, which specify the task of the respective pec service channel. 5.1.1 interrupt control registers all interrupt control registers are organized identically. the lower 8 bits of an interrupt control register contain the complete interrupt status information of the associated source, which is required during one round of prioritization, the upper 8 bits of the respective register are reserved. all interrupt control registers are bit-addressable and all bits can be read or written via software. this allows each interrupt source to be programmed or modified with just one instruction. when accessing interrupt control registers through instructions which operate on word data types, their upper 8 bits (15 8) will return zeros, when read, and will discard written data. the layout of the interrupt control registers shown below applies to each xxic register, where xx stands for the mnemonic for the respective source.
c167cs derivatives interrupt and trap functions users manual 5-7 v2.0, 2000-07 the interrupt request flag is set by hardware whenever a service request from the respective source occurs. it is cleared automatically upon entry into the interrupt service routine or upon a pec service. in the case of pec service the interrupt request flag remains set, if the count field in register peccx of the selected pec channel decrements to zero. this allows a normal cpu interrupt to respond to a completed pec block transfer. note: modifying the interrupt request flag via software causes the same effects as if it had been set or cleared by hardware. the interrupt enable control bit determines whether the respective interrupt node takes part in the arbitration cycles (enabled) or not (disabled). the associated request flag will be set upon a source request in any case. the occurrence of an interrupt request can so be polled via xxir even while the node is disabled. note: in this case the interrupt request flag xxir is not cleared automatically but must be cleared via software. xxic (e)sfr (yyyy h /zz h ) reset value: - - 00 h 1514131211109876543210 xxir xxie ilvl glvl - - - - - - - - rwh rw rw bit function glvl group level defines the internal order for simultaneous requests of the same priority. 3: highest group priority 0: lowest group priority ilvl interrupt priority level defines the priority level for the arbitration of requests. f h : highest priority level 0 h : lowest priority level xxie interrupt enable control bit (individually enables/disables a specific source) 0: interrupt request is disabled 1: interrupt request is enabled xxir interrupt request flag 0: no request pending 1: this source has raised an interrupt request
c167cs derivatives interrupt and trap functions users manual 5-8 v2.0, 2000-07 interrupt priority level and group level the four bits of bit field ilvl specify the priority level of a service request for the arbitration of simultaneous requests. the priority increases with the numerical value of ilvl, so 0000 b is the lowest and 1111 b is the highest priority level. when more than one interrupt request on a specific level gets active at the same time, the values in the respective bit fields glvl are used for second level arbitration to select one request for being serviced. again the group priority increases with the numerical value of glvl, so 00 b is the lowest and 11 b is the highest group priority. note: all interrupt request sources that are enabled and programmed to the same priority level must always be programmed to different group priorities. otherwise an incorrect interrupt vector will be generated. upon entry into the interrupt service routine, the priority level of the source that won the arbitration and whos priority level is higher than the current cpu level, is copied into bit field ilvl of register psw after pushing the old psw contents on the stack. the interrupt system of the c167cs allows nesting of up to 15 interrupt service routines of different priority levels (level 0 cannot be arbitrated). interrupt requests that are programmed to priority levels 15 or 14 (i.e. ilvl = 111x b ) will be serviced by the pec, unless the count field of the associated pecc register contains zero. in this case the request will instead be serviced by normal interrupt processing. interrupt requests that are programmed to priority levels 13 through 1 will always be serviced by normal interrupt processing. note: priority level 0000 b is the default level of the cpu. therefore a request on level 0 will never be serviced, because it can never interrupt the cpu. however, an enabled interrupt request on level 0000 b will terminate the c167css idle mode and reactivate the cpu. for interrupt requests which are to be serviced by the pec, the associated pec channel number is derived from the respective ilvl (lsb) and glvl (see figure 5-1 ). so programming a source to priority level 15 (ilvl = 1111 b ) selects the pec channel group 7 4, programming a source to priority level 14 (ilvl = 1110 b ) selects the pec channel group 3 0. the actual pec channel number is then determined by the group priority field glvl. simultaneous requests for pec channels are prioritized according to the pec channel number, where channel 0 has lowest and channel 8 has highest priority. note: all sources that request pec service must be programmed to different pec channels. otherwise an incorrect pec channel may be activated.
c167cs derivatives interrupt and trap functions users manual 5-9 v2.0, 2000-07 figure 5-1 priority levels and pec channels table 5-3 shows in a few examples, which action is executed with a given programming of an interrupt control register. note: all requests on levels 13 1 cannot initiate pec transfers. they are always serviced by an interrupt service routine. no pecc register is associated and no count field is checked. table 5-3 interrupt priority examples priority level type of service ilvl glvl count = 00 h count 1 00 h 1 1 1 11 1 cpu interrupt, level 15, group priority 3 pec service, channel 7 1 1 1 11 0 cpu interrupt, level 15, group priority 2 pec service, channel 6 1 1 1 01 0 cpu interrupt, level 14, group priority 2 pec service, channel 2 1 1 0 1 1 0 cpu interrupt, level 13, group priority 2 cpu interrupt, level 13, group priority 2 0 0 0 1 1 1 cpu interrupt, level 1, group priority 3 cpu interrupt, level 1, group priority 3 0 0 0 1 0 0 cpu interrupt, level 1, group priority 0 cpu interrupt, level 1, group priority 0 0 0 0 0 x x no service! no service! mca04330 ilvl glvl pec channel # interrupt control register pec control
c167cs derivatives interrupt and trap functions users manual 5-10 v2.0, 2000-07 interrupt control functions in the psw the processor status word (psw) is functionally divided into 2 parts: the lower byte of the psw basically represents the arithmetic status of the cpu, the upper byte of the psw controls the interrupt system of the c167cs and the arbitration mechanism for the external bus interface. note: pipeline effects have to be considered when enabling/disabling interrupt requests via modifications of register psw (see chapter 4 ). psw processor status word sfr (ff10 h /88 h ) reset value: 0000 h 1514131211109876543210 ilvl ien hld en --- usr 0 mul ip ezvcn rw rw rw - - - rw rwh rwh rwh rwh rwh rwh bit function n, c, v, z, e, mulip, usr0 cpu status flags (described in chapter 4 ) define the current status of the cpu (alu, multiplication unit). hlden hold enable (enables external bus arbitration) 0: bus arbitration disabled, p6.7 p6.5 may be used for general purpose io 1: bus arbitration enabled, p6.7 p6.5 serve as breq , hlda , hold , resp. ien interrupt enable control bit (globally enables/disables interrupt requests) 0: interrupt requests are disabled 1: interrupt requests are enabled ilvl cpu priority level defines the current priority level for the cpu f h : highest priority level 0 h : lowest priority level
c167cs derivatives interrupt and trap functions users manual 5-11 v2.0, 2000-07 cpu priority ilvl defines the current level for the operation of the cpu. this bit field reflects the priority level of the routine that is currently executed. upon the entry into an interrupt service routine this bit field is updated with the priority level of the request that is being serviced. the psw is saved on the system stack before. the cpu level determines the minimum interrupt priority level that will be serviced. any request on the same or a lower level will not be acknowledged. the current cpu priority level may be adjusted via software to control which interrupt request sources will be acknowledged. pec transfers do not really interrupt the cpu, but rather steal a single cycle, so pec services do not influence the ilvl field in the psw. hardware traps switch the cpu level to maximum priority (i.e. 15) so no interrupt or pec requests will be acknowledged while an exception trap service routine is executed. note: the trap instruction does not change the cpu level, so software invoked trap service routines may be interrupted by higher requests. interrupt enable bit ien globally enables or disables pec operation and the acceptance of interrupts by the cpu. when ien is cleared, no new interrupt requests are accepted by the cpu. requests that already have entered the pipeline at that time will process, however. when ien is set to 1, all interrupt sources, which have been individually enabled by the interrupt enable bits in their associated control registers, are globally enabled. note: traps are non-maskable and are therefore not affected by the ien bit.
c167cs derivatives interrupt and trap functions users manual 5-12 v2.0, 2000-07 5.2 operation of the pec channels the c167cs s peripheral event controller (pec) provides 8 pec service channels, which move a single byte or word between two locations in segment 0 (data pages 3 0). this is the fastest possible interrupt response and in many cases is sufficient to service the respective peripheral request (e.g. serial channels, etc.). each channel is controlled by a dedicated pec channel counter/control register (peccx) and a pair of pointers for source (srcpx) and destination (dstpx) of the data transfer. the pecc registers control the action that is performed by the respective pec channel. peccx pec control reg. sfr (fecy h /6z h , see table 5-4 ) reset value: 0000 h 1514131211109876543210 inc bwt count - - - - - rw rw rw bit function count pec transfer count counts pec transfers and influences the channels action (see table 5-5 ) bwt byte/word transfer selection 0: transfer a word 1: transfer a byte inc increment control (modification of srcpx or dstpx) 0 0: pointers are not modified 0 1: increment dstpx by 1 or 2 (bwt) 1 0: increment srcpx by 1 or 2 (bwt) 1 1: reserved. do not use this combination. (changed to 10 by hardware) table 5-4 pec control register addresses register address reg. space register address reg. space pecc0 fec0 h /60 h sfr pecc4 fec8 h /64 h sfr pecc1 fec2 h /61 h sfr pecc5 feca h /65 h sfr pecc2 fec4 h /62 h sfr pecc6 fecc h /66 h sfr pecc3 fec6 h /63 h sfr pecc7 fece h /67 h sfr
c167cs derivatives interrupt and trap functions users manual 5-13 v2.0, 2000-07 byte/word transfer bit bwt controls, if a byte or a word is moved during a pec service cycle. this selection controls the transferred data size and the increment step for the modified pointer. increment control field inc controls, if one of the pec pointers is incremented after the pec transfer. it is not possible to increment both pointers, however. if the pointers are not modified (inc = 00), the respective channel will always move data from the same source to the same destination. note: the reserved combination 11 is changed to 10 by hardware. however, it is not recommended to use this combination. the pec transfer count field count controls the action of a respective pec channel, where the content of bit field count at the time the request is activated selects the action. count may allow a specified number of pec transfers, unlimited transfers or no pec service at all. table 5-5 summarizes, how the count field itself, the interrupt requests flag ir and the pec channel action depends on the previous content of count. the pec transfer counter allows to service a specified number of requests by the respective pec channel, and then (when count reaches 00 h ) activate the interrupt service routine, which is associated with the priority level. after each pec transfer the count field is decremented and the request flag is cleared to indicate that the request has been serviced. table 5-5 influence of bitfield count previous count modified count ir after pec service action of pec channel and comments ff h ff h 0 move a byte/word continuous transfer mode, i.e. count is not modified. fe h 02 h fd h 01 h 0 move a byte/word and decrement count 01 h 00 h 1 move a byte/word leave request flag set, which triggers another request. 00 h 00 h (1) no action! activate interrupt service routine rather than pec channel.
c167cs derivatives interrupt and trap functions users manual 5-14 v2.0, 2000-07 continuous transfers are selected by the value ff h in bit field count. in this case count is not modified and the respective pec channel services any request until it is disabled again. when count is decremented from 01 h to 00 h after a transfer, the request flag is not cleared, which generates another request from the same source. when count already contains the value 00 h , the respective pec channel remains idle and the associated interrupt service routine is activated instead. this allows to choose, if a level 15 or 14 request is to be serviced by the pec or by the interrupt service routine. note: pec transfers are only executed, if their priority level is higher than the cpu level, i.e. only pec channels 7 4 are processed, while the cpu executes on level 14. all interrupt request sources that are enabled and programmed for pec service should use different channels. otherwise only one transfer will be performed for all simultaneous requests. when count is decremented to 00 h , and the cpu is to be interrupted, an incorrect interrupt vector will be generated. the source and destination pointers specifiy the locations between which the data is to be moved. a pair of pointers (srcpx and dstpx) is associated with each of the 8 pec channels. these pointers do not reside in specific sfrs, but are mapped into the internal ram of the c167cs just below the bit-addressable area (see figure 5-2 ). figure 5-2 mapping of pec pointers into the internal ram mca04331 dstp7 srcp7 dstp6 srcp6 dstp5 srcp5 dstp4 srcp4 00fcfe h 00fcfc h 00fcfa h 00fcf8 h 00fcf6 h 00fcf4 h 00fcf2 h 00fcf0 h dstp3 srcp3 dstp2 srcp2 dstp1 srcp1 dstp0 srcp0 00fcee h 00fcec h 00fcea h 00fce8 h 00fce6 h 00fce4 h 00fce2 h 00fce0 h
c167cs derivatives interrupt and trap functions users manual 5-15 v2.0, 2000-07 pec data transfers do not use the data page pointers dpp3 dpp0. the pec source and destination pointers are used as 16-bit intra-segment addresses within segment 0, so data can be transferred between any two locations within the first four data pages 30. the pointer locations for inactive pec channels may be used for general data storage. only the required pointers occupy ram locations. note: if word data transfer is selected for a specific pec channel (i.e. bwt = 0), the respective source and destination pointers must both contain a valid word address which points to an even byte boundary. otherwise the illegal word access trap will be invoked, when this channel is used.
c167cs derivatives interrupt and trap functions users manual 5-16 v2.0, 2000-07 5.3 prioritization of interrupt and pec service requests interrupt and pec service requests from all sources can be enabled, so they are arbitrated and serviced (if they win), or they may be disabled, so their requests are disregarded and not serviced. enabling and disabling interrupt requests may be done via three mechanisms: control bits allow to switch each individual source on or off, so it may generate a request or not. the control bits (xxie) are located in the respective interrupt control registers. all interrupt requests may be enabled or disabled generally via bit ien in register psw. this control bit is the main switch that selects, if requests from any source are accepted or not. for a specific request to be arbitrated the respective sources enable bit and the global enable bit must both be set. the priority level automatically selects a certain group of interrupt requests that will be acknowledged, disclosing all other requests. the priority level of the source that won the arbitration is compared against the cpus current level and the source is only serviced, if its level is higher than the current cpu level. changing the cpu level to a specific value via software blocks all requests on the same or a lower level. an interrupt source that is assigned to level 0 will be disabled and never be serviced. the atomic and extend instructions automatically disable all interrupt requests for the duration of the following 1 4 instructions. this is useful e.g. for semaphore handling and does not require to re-enable the interrupt system after the unseparable instruction sequence (see chapter 22 ). interrupt class management an interrupt class covers a set of interrupt sources with the same importance, i.e. the same priority from the systems viewpoint. interrupts of the same class must not interrupt each other. the c167cs supports this function with two features: classes with up to 4 members can be established by using the same interrupt priority (ilvl) and assigning a dedicated group level (glvl) to each member. this functionality is built-in and handled automatically by the interrupt controller. classes with more than 4 members can be established by using a number of adjacent interrupt priorities (ilvl) and the respective group levels (4 per ilvl). each interrupt service routine within this class sets the cpu level to the highest interrupt priority within the class. all requests from the same or any lower level are blocked now, i.e. no request of this class will be accepted.
c167cs derivatives interrupt and trap functions users manual 5-17 v2.0, 2000-07 the example below establishes 3 interrupt classes which cover 2 or 3 interrupt priorities, depending on the number of members in a class. a level 6 interrupt disables all other sources in class 2 by changing the current cpu level to 8, which is the highest priority (ilvl) in class 2. class 1 requests or pec requests are still serviced in this case. the 24 interrupt sources (excluding pec requests) are so assigned to 3 classes of priority rather than to 7 different levels, as the hardware support would do. table 5-6 software controlled interrupt classes (example) ilvl (priority) glvl interpretation 3210 15 pec service on up to 8 channels 14 13 12 xxxxinterrupt class 1 5 sources on 2 levels 11 x 10 9 8 xxxxinterrupt class 2 9 sources on 3 levels 7 xxxx 6x 5 xxxxinterrupt class 3 5 sources on 2 levels 4x 3 2 1 0 no service!
c167cs derivatives interrupt and trap functions users manual 5-18 v2.0, 2000-07 5.4 saving the status during interrupt service before an interrupt request that has been arbitrated is actually serviced, the status of the current task is automatically saved on the system stack. the cpu status (psw) is saved along with the location, where the execution of the interrupted task is to be resumed after returning from the service routine. this return location is specified through the instruction pointer (ip) and, in case of a segmented memory model, the code segment pointer (csp). bit sgtdis in register syscon controls, how the return location is stored. the system stack receives the psw first, followed by the ip (unsegmented) or followed by csp and then ip (segmented mode). this optimizes the usage of the system stack, if segmentation is disabled. the cpu priority field (ilvl in psw) is updated with the priority of the interrupt request that is to be serviced, so the cpu now executes on the new level. if a multiplication or division was in progress at the time the interrupt request was acknowledged, bit mulip in register psw is set to 1. in this case the return location that is saved on the stack is not the next instruction in the instruction flow, but rather the multiply or divide instruction itself, as this instruction has been interrupted and will be completed after returning from the service routine. figure 5-3 task status saved on the system stack the interrupt request flag of the source that is being serviced is cleared. the ip is loaded with the vector associated with the requesting source (the csp is cleared in case of segmentation) and the first instruction of the service routine is fetched from the respective vector location, which is expected to branch to the service routine itself. the data page pointers and the context pointer are not affected. when the interrupt service routine is left (reti is executed), the status information is popped from the system stack in the reverse order, taking into account the value of bit sgtdis. (unsegmented) psw system stack after interrupt entry interrupt entry system stack before a) b) sp high addresses low addresses -- -- -- sp ip -- mcd02226 b) interrupt entry system stack after (segmented) task interrupted status of csp psw ip sp
c167cs derivatives interrupt and trap functions users manual 5-19 v2.0, 2000-07 context switching an interrupt service routine usually saves all the registers it uses on the stack, and restores them before returning. the more registers a routine uses, the more time is wasted with saving and restoring. the c167cs allows to switch the complete bank of cpu registers (gprs) with a single instruction, so the service routine executes within its own, separate context. the instruction scxt cp, #new_bank pushes the content of the context pointer (cp) on the system stack and loads cp with the immediate value new_bank, which selects a new register bank. the service routine may now use its own registers. this register bank is preserved, when the service routine terminates, i.e. its contents are available on the next call. before returning (reti) the previous cp is simply popped from the system stack, which returns the registers to the original bank. note: the first instruction following the scxt instruction must not use a gpr. resources that are used by the interrupting program must eventually be saved and restored, e.g. the dpps and the registers of the mul/div unit.
c167cs derivatives interrupt and trap functions users manual 5-20 v2.0, 2000-07 5.5 interrupt response times the interrupt response time defines the time from an interrupt request flag of an enabled interrupt source being set until the first instruction (i1) being fetched from the interrupt vector location. the basic interrupt response time for the c167cs is 3 instruction cycles. figure 5-4 pipeline diagram for interrupt response time all instructions in the pipeline including instruction n (during which the interrupt request flag is set) are completed before entering the service routine. the actual execution time for these instructions (e.g. waitstates) therefore influences the interrupt response time. in figure 5-4 the respective interrupt request flag is set in cycle 1 (fetching of instruction n). the indicated source wins the prioritization round (during cycle 2). in cycle 3 a trap instruction is injected into the decode stage of the pipeline, replacing instruction n + 1 and clearing the source s interrupt request flag to 0. cycle 4 completes the injected trap instruction (save psw, ip and csp, if segmented mode) and fetches the first instruction (i1) from the respective vector location. all instructions that entered the pipeline after setting of the interrupt request flag (n + 1, n + 2) will be executed after returning from the interrupt service routine. the minimum interrupt response time is 5 states (10 tcl). this requires program execution from the internal code memory, no external operand read requests and setting the interrupt request flag during the last state of an instruction cycle. when the interrupt request flag is set during the first state of an instruction cycle, the minimum interrupt response time under these conditions is 6 state times (12 tcl). the interrupt response time is increased by all delays of the instructions in the pipeline that are executed before entering the service routine (including n). mct04332 pipeline stage fetch decode execute writeback cycle 1 n n - 1 n - 2 n - 3 cycle 2 n + 1 n n - 1 n - 2 cycle 3 n + 2 trap (1) n n - 1 cycle 4 i1 trap (2) trap n 0 1 ir-flag interrupt response time
c167cs derivatives interrupt and trap functions users manual 5-21 v2.0, 2000-07 ? when internal hold conditions between instruction pairs n C 2/n C 1 or n C 1/n occur, or instruction n explicitly writes to the psw or the sp, the minimum interrupt response time may be extended by 1 state time for each of these conditions. ? when instruction n reads an operand from the internal code memory, or when n is a call, return, trap, or mov rn, [rm+ #data16] instruction, the minimum interrupt response time may additionally be extended by 2 state times during internal code memory program execution. ? in case instruction n reads the psw and instruction n C 1 has an effect on the condition flags, the interrupt response time may additionally be extended by 2 state times. the worst case interrupt response time during internal code memory program execution adds to 12 state times (24 tcl). any reference to external locations increases the interrupt response time due to pipeline related access priorities. the following conditions have to be considered: ? instruction fetch from an external location ? operand read from an external location ? result write-back to an external location depending on where the instructions, source and destination operands are located, there are a number of combinations. note, however, that only access conflicts contribute to the delay. a few examples illustrate these delays: ? the worst case interrupt response time including external accesses will occur, when instructions n, n + 1 and n + 2 are executed out of external memory, instructions n C 1 and n require external operand read accesses, instructions n C 3 through n write back external operands, and the interrupt vector also points to an external location. in this case the interrupt response time is the time to perform 9 word bus accesses, because instruction i1 cannot be fetched via the external bus until all write, fetch and read requests of preceding instructions in the pipeline are terminated. ? when the above example has the interrupt vector pointing into the internal code memory, the interrupt response time is 7 word bus accesses plus 2 states, because fetching of instruction i1 from internal code memory can start earlier. ? when instructions n, n + 1 and n + 2 are executed out of external memory and the interrupt vector also points to an external location, but all operands for instructions n C 3 through n are in internal memory, then the interrupt response time is the time to perform 3 word bus accesses. ? when the above example has the interrupt vector pointing into the internal code memory, the interrupt response time is 1 word bus access plus 4 states.
c167cs derivatives interrupt and trap functions users manual 5-22 v2.0, 2000-07 after an interrupt service routine has been terminated by executing the reti instruction, and if further interrupts are pending, the next interrupt service routine will not be entered until at least two instruction cycles have been executed of the program that was interrupted. in most cases two instructions will be executed during this time. only one instruction will typically be executed, if the first instruction following the reti instruction is a branch instruction (without cache hit), or if it reads an operand from internal code memory, or if it is executed out of the internal ram. note: a bus access in this context includes all delays which can occur during an external bus cycle.
c167cs derivatives interrupt and trap functions users manual 5-23 v2.0, 2000-07 5.6 pec response times the pec response time defines the time from an interrupt request flag of an enabled interrupt source being set until the pec data transfer being started. the basic pec response time for the c167cs is 2 instruction cycles. figure 5-5 pipeline diagram for pec response time in figure 5-5 above the respective interrupt request flag is set in cycle 1 (fetching of instruction n). the indicated source wins the prioritization round (during cycle 2). in cycle 3 a pec transfer instruction is injected into the decode stage of the pipeline, suspending instruction n + 1 and clearing the sources interrupt request flag to 0. cycle 4 completes the injected pec transfer and resumes the execution of instruction n+1. all instructions that entered the pipeline after setting of the interrupt request flag (n + 1, n + 2) will be executed after the pec data transfer. note: when instruction n reads any of the pec control registers pecc7 pecc0, while a pec request wins the current round of prioritization, this round is repeated and the pec data transfer is started one cycle later. the minimum pec response time is 3 states (6 tcl). this requires program execution from the internal code memory, no external operand read requests and setting the interrupt request flag during the last state of an instruction cycle. when the interrupt request flag is set during the first state of an instruction cycle, the minimum pec response time under these conditions is 4 state times (8 tcl). the pec response time is increased by all delays of the instructions in the pipeline that are executed before starting the data transfer (including n). mct04333 pipeline stage fetch decode execute writeback cycle 1 n n - 1 n - 2 n - 3 cycle 2 n + 1 n n - 1 n - 2 cycle 3 n + 2 pec n n - 1 cycle 4 n + 2 n + 1 pec n 0 1 ir-flag pec response time
c167cs derivatives interrupt and trap functions users manual 5-24 v2.0, 2000-07 ? when internal hold conditions between instruction pairs n C 2/nC 1 or n C 1/n occur, the minimum pec response time may be extended by 1 state time for each of these conditions. ? when instruction n reads an operand from the internal code memory, or when n is a call, return, trap, or mov rn, [rm+ #data16] instruction, the minimum pec response time may additionally be extended by 2 state times during internal code memory program execution. ? in case instruction n reads the psw and instruction n C 1 has an effect on the condition flags, the pec response time may additionally be extended by 2 state times. the worst case pec response time during internal code memory program execution adds to 9 state times (18 tcl). any reference to external locations increases the pec response time due to pipeline related access priorities. the following conditions have to be considered: ? instruction fetch from an external location ? operand read from an external location ? result write-back to an external location depending on where the instructions, source and destination operands are located, there are a number of combinations. note, however, that only access conflicts contribute to the delay. a few examples illustrate these delays: ? the worst case interrupt response time including external accesses will occur, when instructions n and n + 1 are executed out of external memory, instructions n C 1 and n require external operand read accesses and instructions n C 3, n C 2 and n C 1 write back external operands. in this case the pec response time is the time to perform 7 word bus accesses. ? when instructions n and n + 1 are executed out of external memory, but all operands for instructions n C 3 through n C 1 are in internal memory, then the pec response time is the time to perform 1 word bus access plus 2 state times. once a request for pec service has been acknowledged by the cpu, the execution of the next instruction is delayed by 2 state times plus the additional time it might take to fetch the source operand from internal code memory or external memory and to write the destination operand over the external bus in an external program environment. note: a bus access in this context includes all delays which can occur during an external bus cycle.
c167cs derivatives interrupt and trap functions users manual 5-25 v2.0, 2000-07 5.7 interrupt node sharing interrupt nodes may be shared between several module requests either if the requests are generated mutually exclusive or if the requests are generated at a low rate. if more than one source is enabled in this case the interrupt handler will first have to determine the requesting source. however, this overhead is not critical for low rate requests. this node sharing is controlled via the sub-node interrupt control register isnc which provides a separate request flag and enable bit for each supported request source. the interrupt level used for arbitration is determined by the node control register ( ic). note: in order to ensure compatibility with other derivatives application software should never set reserved bits within register isnc. isnc interrupt sub-node ctrl. reg. esfr (f1de h /ef h ) reset value: 0000 h 1514131211109876543210 ------------ pll ie pll ir rtc ie rtc ir - - - - - - - - - - - - rw rw rw rw bit function xxir interrupt request flag for source xx 0: no request from source xx pending. 1: source xx has raised an interrupt request. xxie interrupt enable control bit for source xx 0: source xx interrupt request is disabled. 1: source xx interrupt request is enabled. table 5-7 sub-node control bit allocation bit pos. interrupt source associated node 15 4 reserved. reserved. 3|2 pll / owd xp3ic 1|0 rtc xp3ic
c167cs derivatives interrupt and trap functions users manual 5-26 v2.0, 2000-07 5.8 external interrupts although the c167cs has no dedicated intr input pins, it provides many possibilities to react on external asynchronous events by using a number of io lines for interrupt input. the interrupt function may either be combined with the pins main function or may be used instead of it, i.e. if the main pin function is not required. interrupt signals may be connected to: ? cc31io cc16io, the capture input/compare output lines of the capcom2 unit, ? cc15io cc0io, the capture input/compare output lines of the capcom1 unit, ? t4in, t2in, the timer input pins, ? capin, the capture input of gpt2 for each of these pins either a positive, a negative, or both a positive and a negative external transition can be selected to cause an interrupt or pec service request. the edge selection is performed in the control register of the peripheral device associated with the respective port pin. the peripheral must be programmed to a specific operating mode to allow generation of an interrupt by the external signal. the priority of the interrupt request is determined by the interrupt control register of the respective peripheral interrupt source, and the interrupt vector of this source will be used to service the external interrupt request. note: in order to use any of the listed pins as external interrupt input, it must be switched to input mode via its direction control bit dpx.y in the respective port direction control register dpx. when port pins ccxio are to be used as external interrupt input pins, bit field ccmodx in the control register of the corresponding capture/compare register ccx must select capture mode. when ccmodx is programmed to 001 b , the interrupt request flag ccxir in register ccxic will be set on a positive external transition at pin ccxio. when ccmodx is programmed to 010 b , a negative external transition will set the interrupt request flag. when ccmodx = 011 b , both a positive and a negative transition will set table 5-8 pins to be used as external interrupt inputs port pin original function control register p7.7-4/cc31-28io capcom register 31-28 capture input cc31-cc28 p1h.7-4/cc27-24io capcom register 27-24 capture input cc27-cc24 p8.7-0/cc23-16io capcom register 23-16 capture input cc23-cc16 p2.15-0/cc15-0io capcom register 15-0 capture input cc15-cc0 p3.7/t2in auxiliary timer t2 input pin t2con p3.5/t4in auxiliary timer t4 input pin t4con p3.2/capin gpt2 capture input pin t5con
c167cs derivatives interrupt and trap functions users manual 5-27 v2.0, 2000-07 the request flag. in all three cases, the contents of the allocated capcom timer will be latched into capture register ccx, independent whether the timer is running or not. when the interrupt enable bit ccxie is set, a pec request or an interrupt request for vector ccxint will be generated. pins t2in or t4in can be used as external interrupt input pins when the associated auxiliary timer t2 or t4 in block gpt1 is configured for capture mode. this mode is selected by programming the mode control fields t2m or t4m in control registers t2con or t4con to 101 b . the active edge of the external input signal is determined by bit fields t2i or t4i. when these fields are programmed to x01 b , interrupt request flags t2ir or t4ir in registers t2ic or t4ic will be set on a positive external transition at pins t2in or t4in, respectively. when t2i or t4i are programmed to x10 b , then a negative external transition will set the corresponding request flag. when t2i or t4i are programmed to x11 b , both a positive and a negative transition will set the request flag. in all three cases, the contents of the core timer t3 will be captured into the auxiliary timer registers t2 or t4 based on the transition at pins t2in or t4in. when the interrupt enable bits t2ie or t4ie are set, a pec request or an interrupt request for vector t2int or t4int will be generated. pin capin differs slightly from the timer input pins as it can be used as external interrupt input pin without affecting peripheral functions. when the capture mode enable bit t5sc in register t5con is cleared to 0, signal transitions on pin capin will only set the interrupt request flag crir in register cric, and the capture function of register caprel is not activated. so register caprel can still be used as reload register for gpt2 timer t5, while pin capin serves as external interrupt input. bit field ci in register t5con selects the effective transition of the external interrupt input signal. when ci is programmed to 01 b , a positive external transition will set the interrupt request flag. ci = 10 b selects a negative transition to set the interrupt request flag, and with ci = 11 b , both a positive and a negative transition will set the request flag. when the interrupt enable bit crie is set, an interrupt request for vector crint or a pec request will be generated. note: the non-maskable interrupt input pin nmi (sample rate 2 tcl) and the reset input rstin provide another possibility for the cpu to react on an external input signal. nmi and rstin are dedicated input pins, which cause hardware traps.
c167cs derivatives interrupt and trap functions users manual 5-28 v2.0, 2000-07 fast external interrupts the input pins that may be used for external interrupts are sampled every 16 tcl, i.e. external events are scanned and detected in timeframes of 16 tcl (8 tcl for capin). the c167cs provides 8 interrupt inputs that are sampled every 2 tcl, so external events are captured faster than with standard interrupt inputs. the upper 8 pins of port 2 (p2.15-p2.8) can individually be programmed to this fast interrupt mode, where also the trigger transition (rising, falling or both) can be selected. the external interrupt control register exicon controls this feature for all 8 pins. note: the fast external interrupt inputs are sampled every 2 tcl. the interrupt request arbitration and processing, however, is executed every 8 tcl. these fast external interrupts use the interrupt nodes and vectors of the capcom channels cc8-cc15, so the capture/compare function cannot be used on the respective port 2 pins (with exixes 1 00 b ). however, general purpose io is possible in all cases. exicon ext. interrupt control reg. esfr (f1c0 h /e0 h ) reset value: 0000 h 1514131211109876543210 exi7es exi6es exi5es exi4es exi3es exi2es exi1es exi0es rw rw rw rw rw rw rw rw bit function exixes external interrupt x edge selection field (x = 7 0) 0 0: fast external interrupts disabled: standard mode 0 1: interrupt on positive edge (rising) 1 0: interrupt on negative edge (falling) 1 1: interrupt on any edge (rising or falling)
c167cs derivatives interrupt and trap functions users manual 5-29 v2.0, 2000-07 external interrupt source control the input source for fast external interrupts (controlled via register exicon) can be derived either from the associated port pin exnin or from an alternate source. this selection is controlled via register exisel. activating the alternate input source e.g. permits the detection of transitions on the interface lines of disabled interfaces. upon this trigger the respective interface can be reactivated and respond to the detected activity. table 5-9 summarizes the association of the bitfields of register exisel with the respective interface input lines. exisel ext. interrupt source reg. esfr (f1da h /ed h ) reset value: 0000 h 1514131211109876543210 exi7ss exi6ss exi5ss exi4ss exi3ss exi2ss exi1ss exi0ss rw rw rw rw rw rw rw rw bit function exixss external interrupt x source selection field (x = 7 0) 00: input from associated exzin pin. 01: input from alternate pin. 10: input from pin exzin ored with alternate pin. 11: input from pin exzin anded with alternate pin. table 5-9 connection of interface inputs to external interrupt nodes bitfield associated interface line notes exi0ss can1_rxd the used pin depends on the assignment for the respective module. exi1ss can2_rxd exi2ss rxd0 asc0 exi3ss sclk ssc
c167cs derivatives interrupt and trap functions users manual 5-30 v2.0, 2000-07 external interrupts during sleep mode during sleep mode all peripheral clock signals are deactivated which also disables the standard edge detection logic for the fast external interrupts. however, transitions on these interrupt inputs must be recognized in order to initiate the wakeup. therefore during sleep mode a special edge detection logic for the fast external interrupts (exzin) is activated, which requires no clock signal (therefore also works in sleep mode) and is equipped with an analog noise filter. this filter suppresses spikes (generated by noise) up to 10 ns. input pulses with a duration of 100 ns minimum are recognized and generate an interrupt request. this filter delays the recognition of an external wakeup signal by approx. 100 ns, but the spike suppression ensures safe and robust operation of the sleep/wakeup mechanism in an active environment. figure 5-6 input noise filter operation mcd04456 input signal interrupt request rejected recognized 10 ns 100 ns
c167cs derivatives interrupt and trap functions users manual 5-31 v2.0, 2000-07 5.9 trap functions traps interrupt the current execution similar to standard interrupts. however, trap functions offer the possibility to bypass the interrupt system s prioritization process in cases where immediate system reaction is required. trap functions are not maskable and always have priority over interrupt requests on any priority level. the c167cs provides two different kinds of trapping mechanisms. hardware traps are triggered by events that occur during program execution (e.g. illegal access or undefined opcode), software traps are initiated via an instruction within the current execution flow. software traps the trap instruction is used to cause a software call to an interrupt service routine. the trap number that is specified in the operand field of the trap instruction determines which vector location in the address range from 000000 h through 0001fc h will be branched to. executing a trap instruction causes a similar effect as if an interrupt at the same vector had occurred. psw, csp (in segmentation mode), and ip are pushed on the internal system stack and a jump is taken to the specified vector location. when segmentation is enabled and a trap is executed, the csp for the trap service routine is set to code segment 0. no interrupt request flags are affected by the trap instruction. the interrupt service routine called by a trap instruction must be terminated with a reti (return from interrupt) instruction to ensure correct operation. note: the cpu level in register psw is not modified by the trap instruction, so the service routine is executed on the same priority level from which it was invoked. therefore, the service routine entered by the trap instruction can be interrupted by other traps or higher priority interrupts, other than when triggered by a hardware trap. hardware traps hardware traps are issued by faults or specific system states that occur during runtime of a program (not identified at assembly time). a hardware trap may also be triggered intentionally, e.g. to emulate additional instructions by generating an illegal opcode trap. the c167cs distinguishes eight different hardware trap functions. when a hardware trap condition has been detected, the cpu branches to the trap vector location for the respective trap condition. depending on the trap condition, the instruction which caused the trap is either completed or cancelled (i.e. it has no effect on the system state) before the trap handling routine is entered. hardware traps are non-maskable and always have priority over every other cpu activity. if several hardware trap conditions are detected within the same instruction cycle, the highest priority trap is serviced (see table 5-2 ).
c167cs derivatives interrupt and trap functions users manual 5-32 v2.0, 2000-07 psw, csp (in segmentation mode), and ip are pushed on the internal system stack and the cpu level in register psw is set to the highest possible priority level (i.e. level 15), disabling all interrupts. the csp is set to code segment zero, if segmentation is enabled. a trap service routine must be terminated with the reti instruction. the eight hardware trap functions of the c167cs are divided into two classes: class a traps are ? external non-maskable interrupt (nmi ) ? stack overflow ? stack underflow trap these traps share the same trap priority, but have an individual vector address. class b traps are ? undefined opcode ? protection fault ? illegal word operand access ? illegal instruction access ? illegal external bus access trap these traps share the same trap priority, and the same vector address. the bit-addressable trap flag register (tfr) allows a trap service routine to identify the kind of trap which caused the exception. each trap function is indicated by a separate request flag. when a hardware trap occurs, the corresponding request flag in register tfr is set to 1. the reset functions (hardware, software, watchdog) may be regarded as a type of trap. reset functions have the highest system priority (trap priority iii). class a traps have the second highest priority (trap priority ii), on the 3 rd rank are class b traps, so a class a trap can interrupt a class b trap. if more than one class a trap occur at a time, they are prioritized internally, with the nmi trap on the highest and the stack underflow trap on the lowest priority. all class b traps have the same trap priority (trap priority i). when several class b traps get active at a time, the corresponding flags in the tfr register are set and the trap service routine is entered. since all class b traps have the same vector, the priority of service of simultaneously occurring class b traps is determined by software in the trap service routine. a class a trap occurring during the execution of a class b trap service routine will be serviced immediately. during the execution of a class a trap service routine, however, any class b trap occurring will not be serviced until the class a trap service routine is exited with a reti instruction. in this case, the occurrence of the class b trap condition is stored in the tfr register, but the ip value of the instruction which caused this trap is lost.
c167cs derivatives interrupt and trap functions users manual 5-33 v2.0, 2000-07 note: the trap service routine must clear the respective trap flag, otherwise a new trap will be requested after exiting the service routine. setting a trap request flag by software causes the same effects as if it had been set by hardware. in the case where e.g. an undefined opcode trap (class b) occurs simultaneously with an nmi trap (class a), both the nmi and the undopc flag is set, the ip of the instruction with the undefined opcode is pushed onto the system stack, but the nmi trap is executed. after return from the nmi service routine, the ip is popped from the stack and immediately pushed again because of the pending undopc trap. tfr trap flag register sfr (ffac h /d6 h ) reset value: 0000 h 1514131211109876543210 nmi stk of stk uf ----- und opc --- prt flt ill opa ill ina ill bus rwh rwh rwh - - - - rwh - - - rwh rwh rwh rwh bit function illbus illegal external bus access flag an external access has been attempted with no external bus defined. illina illegal instruction access flag a branch to an odd address has been attempted. illopa illegal word operand access flag a word operand access (read or write) to an odd address has been attempted. prtflt protection fault flag a protected instruction with an illegal format has been detected. undopc undefined opcode flag the currently decoded instruction has no valid c167cs opcode. stkuf stack underflow flag the current stack pointer value exceeds the content of register stkun. stkof stack overflow flag the current stack pointer value falls below the content of reg. stkov. nmi non maskable interrupt flag a negative transition (falling edge) has been detected on pin nmi .
c167cs derivatives interrupt and trap functions users manual 5-34 v2.0, 2000-07 external nmi trap whenever a high to low transition on the dedicated external nmi pin (non-maskable interrupt) is detected, the nmi flag in register tfr is set and the cpu will enter the nmi trap routine. the ip value pushed on the system stack is the address of the instruction following the one after which normal processing was interrupted by the nmi trap. note: the nmi pin is sampled with every cpu clock cycle to detect transitions. stack overflow trap whenever the stack pointer is decremented to a value which is less than the value in the stack overflow register stkov, the stkof flag in register tfr is set and the cpu will enter the stack overflow trap routine. which ip value will be pushed onto the system stack depends on which operation caused the decrement of the sp. when an implicit decrement of the sp is made through a push or call instruction, or upon interrupt or trap entry, the ip value pushed is the address of the following instruction. when the sp is decremented by a subtract instruction, the ip value pushed represents the address of the instruction after the instruction following the subtract instruction. for recovery from stack overflow it must be ensured that there is enough excess space on the stack for saving the current system state (psw, ip, in segmented mode also csp) twice. otherwise, a system reset should be generated. stack underflow trap whenever the stack pointer is incremented to a value which is greater than the value in the stack underflow register stkun, the stkuf flag is set in register tfr and the cpu will enter the stack underflow trap routine. again, which ip value will be pushed onto the system stack depends on which operation caused the increment of the sp. when an implicit increment of the sp is made through a pop or return instruction, the ip value pushed is the address of the following instruction. when the sp is incremented by an add instruction, the pushed ip value represents the address of the instruction after the instruction following the add instruction. undefined opcode trap when the instruction currently decoded by the cpu does not contain a valid c167cs opcode, the undopc flag is set in register tfr and the cpu enters the undefined opcode trap routine. the ip value pushed onto the system stack is the address of the instruction that caused the trap. this can be used to emulate unimplemented instructions. the trap service routine can examine the faulting instruction to decode operands for unimplemented opcodes based on the stacked ip. in order to resume processing, the stacked ip value must be incremented by the size of the undefined instruction, which is determined by the user, before a reti instruction is executed.
c167cs derivatives interrupt and trap functions users manual 5-35 v2.0, 2000-07 protection fault trap whenever one of the special protected instructions is executed where the opcode of that instruction is not repeated twice in the second word of the instruction and the byte following the opcode is not the complement of the opcode, the prtflt flag in register tfr is set and the cpu enters the protection fault trap routine. the protected instructions include diswdt, einit, idle, pwrdn, srst, and srvwdt. the ip value pushed onto the system stack for the protection fault trap is the address of the instruction that caused the trap. illegal word operand access trap whenever a word operand read or write access is attempted to an odd byte address, the illopa flag in register tfr is set and the cpu enters the illegal word operand access trap routine. the ip value pushed onto the system stack is the address of the instruction following the one which caused the trap. illegal instruction access trap whenever a branch is made to an odd byte address, the illina flag in register tfr is set and the cpu enters the illegal instruction access trap routine. the ip value pushed onto the system stack is the illegal odd target address of the branch instruction. illegal external bus access trap whenever the cpu requests an external instruction fetch, data read or data write, and no external bus configuration has been specified, the illbus flag in register tfr is set and the cpu enters the illegal bus access trap routine. the ip value pushed onto the system stack is the address of the instruction following the one which caused the trap.
c167cs derivatives clock generation users manual 6-1 v2.0, 2000-07 6 clock generation all activities of the c167css controller hardware and its on-chip peripherals are controlled via the system clock signal f cpu . this reference clock is generated in three stages (see also figure 6-1 ): oscillator the on-chip pierce oscillator can either run with an external crystal and appropriate oscillator circuitry or it can be driven by an external oscillator or another clock source. frequency control the input clock signal feeds the controller hardware: ? directly, providing phase coupled operation on not too high input frequency ? divided by 2 in order to get 50% duty cycle clock signal ? via an on-chip phase locked loop (pll) providing max. performance on low input frequency ? via the slow down divider (sdd) in order to reduce the power consumption. the resulting internal clock signal is referred to as cpu clock f cpu . clock drivers the cpu clock is distributed via separate clock drivers which feed the cpu itself and two groups of peripheral modules. the rtc is fed with the prescaled oscillator clock ( f rtc ) via a separate clock driver, so it is not affected by the clock control functions. figure 6-1 cpu clock generation stages mcd04457 osc prescaler pll sdd idle mode cpu pcddis peripherals, ports, intrl. ctrl. interfaces ccd pcd icd p. d. mode rtc 32:1 oscillator frequency control clock drivers f rtc
c167cs derivatives clock generation users manual 6-2 v2.0, 2000-07 6.1 oscillator the main oscillator of the c167cs is a power optimized pierce oscillator providing an inverter and a feedback element. pins xtal1 and xtal2 connect the inverter to the external crystal. the standard external oscillator circuitry (see figure 6-2 ) comprises the crystal, two low end capacitors and series resistor ( r x2) to limit the current through the crystal. the additional lc combination is only required for 3rd overtone crystals to suppress oscillation in the fundamental mode. a test resistor ( r q ) may be temporarily inserted to measure the oscillation allowance of the oscillator circuitry. figure 6-2 external oscillator circuitry the on-chip oscillator is optimized for an input frequency range of 4 to 40 mhz. an external clock signal (e.g. from an external oscillator or from a master device) may be fed to the input xtal1. the pierce oscillator then is not required to support the oscillation itself but is rather driven by the input signal. in this case the input frequency range may be 0 to 50 mhz (please note that the maximum applicable input frequency is limited by the devices maximum cpu frequency). note: oscillator measurement within the final target system is recommended to determine the actual oscillation allowance for the oscillator-crystal system. the measurement technique, examples for evaluated systems, and recommendations are provided in a specific application note about oscillators (available via your representative or www). mcs04335 xtal1 xtal2 rx2 r q
c167cs derivatives clock generation users manual 6-3 v2.0, 2000-07 for input frequencies above 25 30 mhz the oscillators output should be terminated as shown in figure 6-3 , at lower frequencies it may be left open. this termination improves the operation of the oscillator by filtering out frequencies above the intended oscillator frequency. figure 6-3 oscillator output termination note: it is strongly recommended to measure the oscillation allowance (or margin) in the final target system (layout) to determine the optimum parameters for the oscillator operation. mcs04336 xtal1 input clock xtal2 15 pf 3 k w
c167cs derivatives clock generation users manual 6-4 v2.0, 2000-07 6.2 frequency control the cpu clock is generated from the oscillator clock in either of two software selectable ways: the basic clock is the standard operating clock for the c167cs and is required to deliver the intended maximum performance. the clock configuration in register rp0h (bitfield clkcfg = rp0h.7-5) determines one of three possible basic clock generation modes: ? direct drive: the oscillator clock is directly fed to the controller hardware. ? prescaler: the oscillator clock is divided by 2 to achieve a 50% duty cycle. ? pll: the oscillator clock is multiplied by a configurable factor of f = 1.5 5. the slow down clock is the oscillator clock divided by a programmable factor of 1 32 (additional 2:1 divider in prescaler mode). this alternate possibility runs the c167cs at a lower frequency (depending on the programmed slow down factor) and thus greatly reduces its power consumption. figure 6-4 frequency control paths note: the configuration register rp0h is loaded with the logic levels present on the upper half of port0 (p0h) after a long hardware reset, i.e. bitfield clkcfg represents the logic levels on pins p0.15-13 (p0h.7-5). mcd04458 configuration pll sdd 2:1 cpu clock f cpu oscillator clock f osc owd software
c167cs derivatives clock generation users manual 6-5 v2.0, 2000-07 the internal operation of the c167cs is controlled by the internal cpu clock f cpu . both edges of the cpu clock can trigger internal (e.g. pipeline) or external (e.g. bus cycles) operations (see figure 6-5 ). figure 6-5 generation mechanisms for the cpu clock mcd04459 f osc f cpu phase locked loop operation t cl t cl f osc f cpu t cl t cl direct clock drive f osc f cpu prescaler operation t cl t cl f osc sdd operation f cpu f cpu t cl t cl t cl t cl (clkrel = 2, direct drive (clkrel = 2, prescaler
c167cs derivatives clock generation users manual 6-6 v2.0, 2000-07 direct drive when direct drive is configured (clkcfg = 011 b ) the c167css clock system is directly fed from the external clock input, i.e. f cpu = f osc . this allows operation of the c167cs with a reasonably small fundamental mode crystal. the specified minimum values for the cpu clock phases (tcls) must be respected. therefore the maximum input clock frequency depends on the clock signals duty cycle. prescaler operation when prescaler operation is configured (clkcfg = 001 b ) the c167css input clock is divided by 2 to generate then cpu clock signal, i.e. f cpu = f osc / 2. this requires the oscillator (or input clock) to run on 2 times the intended operating frequency but guarantees a 50% duty cycle for the internal clock system independent of the input clock signals waveform. pll operation when pll operation is configured (via clkcfg) the c167css input clock is fed to the on-chip phase locked loop circuit which multiplies its frequency by a factor of f =1.55 (selectable via clkcfg, see table 6-1 ) and generates a cpu clock signal with 50% duty cycle, i.e. f cpu = f osc f . the on-chip pll circuit allows operation of the c167cs on a low frequency external clock while still providing maximum performance. the pll also provides fail safe mechanisms which allow the detection of frequency deviations and the execution of emergency actions in case of an external clock failure. when the pll detects a missing input clock signal it generates an interrupt request. this warning interrupt indicates that the pll frequency is no more locked, i.e. no more stable. this occurs when the input clock is unstable and especially when the input clock fails completely, e.g. due to a broken crystal. in this case the synchronization mechanism will reduce the pll output frequency down to the plls base frequency (2 5 mhz). the base frequency is still generated and allows the cpu to execute emergency actions in case of a loss of the external clock. on power-up the pll provides a stable clock signal within ca. 1 ms after v dd has reached the specified valid range, even if there is no external clock signal (in this case the pll will run on its base frequency of 2 5 mhz). the pll starts synchronizing with the external clock signal as soon as it is available. within ca. 1 ms after stable oscillations of the external clock within the specified frequency range the pll will be synchronous with this clock at a frequency of f f osc , i.e. the pll locks to the external clock. when pll operation is selected the cpu clock is a selectable multiple of the oscillator frequency, i.e. the input frequency. table 6-1 lists the possible selections.
c167cs derivatives clock generation users manual 6-7 v2.0, 2000-07 the pll constantly synchronizes to the external clock signal. due to the fact that the external frequency is 1/ f th of the pll output frequency the output frequency may be slightly higher or lower than the desired frequency. this jitter is irrelevant for longer time periods. for short periods (1 4 cpu clock cycles) it remains below 4%. figure 6-6 pll block diagram table 6-1 c167cs clock generation modes rp0h.7-5 (p0h.7-5) cpu frequency f cpu = f osc f external clock input range 1) 1) the external clock input range refers to a cpu clock range of 10 33 mhz. notes 1 1 1 f osc 4 2.5 to 8.25 mhz default configuration 1 1 0 f osc 3 3.33 to 11 mhz C 10 1 f osc 2 5 to 16.5 mhz C 1 0 0 f osc 5 2 to 6.6 mhz C 0 1 1 f osc 1 1 to 33 mhz direct drive 2) 2) the maximum frequency depends on the duty cycle of the external clock signal. in emulation mode pin p0.15 (p0h.7) is inverted, i.e. the configuration 111 would select direct drive in emulation mode. 0 1 0 f osc 1.5 6.66 to 22 mhz C 0 0 1 f osc / 2 2 to 66 mhz cpu clock via prescaler 0 0 0 f osc 2.5 4 to 13.2 mhz C mcb04339 f in pll circuit f pll = f f in reset pwrdn f pll f cpu owd reset sleep lock xp3int clkcfg (rp0h.7-5) f
c167cs derivatives clock generation users manual 6-8 v2.0, 2000-07 6.3 oscillator watchdog the c167cs provides an oscillator watchdog (owd) which monitors the clock signal fed to input xtal1 of the on-chip oscillator (either with a crystal or via external clock drive) in prescaler or direct drive mode (not if the pll provides the basic clock). for this operation the pll provides a clock signal (base frequency) which is used to supervise transitions on the oscillator clock. this pll clock is independent from the xtal1 clock. when the expected oscillator clock transitions are missing the owd activates the pll unlock/owd interrupt node and supplies the cpu with the pll clock signal instead of the selected oscillator clock (see figure 6-4 ). under these circumstances the pll will oscillate with its base frequency. in direct drive mode the pll base frequency is used directly ( f cpu = 2 5 mhz). in prescaler mode the pll base frequency is divided by 2 ( f cpu = 1 2.5 mhz). if the oscillator clock fails while the pll provides the basic clock the system will be supplied with the pll base frequency anyway. with this pll clock signal the cpu can either execute a controlled shutdown sequence bringing the system into a defined and safe idle state, or it can provide an emergency operation of the system with reduced performance based on this (normally slower) emergency clock. note: the cpu clock source is only switched back to the oscillator clock after a hardware reset. the oscillator watchdog can be disabled by setting bit owddis in register syscon. in this case the pll remains idle and provides no clock signal, while the cpu clock signal is derived directly from the oscillator clock or via prescaler or sdd. also no interrupt request will be generated in case of a missing oscillator clock. note: at the end of an external reset bit owddis reflects the inverted level of pin rd at that time. thus the oscillator watchdog may also be disabled via hardware by (externally) pulling the rd line low upon a reset, similar to the standard reset configuration via port0. the oscillator watchdog cannot provide full security while the cpu clock signal is generated by the slowdown divider, because the owd cannot switch to the pll clock in this case (see figure 6-4 ). owd interrupts are only recognizable if f osc is still available (e.g. input frequency too low or intermittent failure only). a broken crystal cannot be detected by software (owd interrupt server) as no sdd clock is available in such a case.
c167cs derivatives clock generation users manual 6-9 v2.0, 2000-07 6.4 clock drivers the operating clock signal f cpu is distributed to the controller hardware via several clock drivers which are disabled under certain circumstances. the real time clock rtc is clocked via a separate clock driver which delivers the prescaled oscillator clock (contrary to the other clock drivers). table 6-2 summarizes the different clock drivers and their function, especially in power reduction modes: note: disabling pcd by setting bit pcddis stops the clock signal for all connected modules. make sure that all these modules are in a safe state before stopping their clock signal. the port input and output values will not change while pcd is disabled (asc0 and ssc will still operate, if active), clkout will be high if enabled. please also respect the hints given in section section 21.5 . table 6-2 clock drivers description clock driver clock signal active mode idle mode power down and sleep mode connected circuitry ccd cpu clock driver f cpu on off off cpu, internal memory modules (iram, rom/otp/flash) icd interface clock driver f cpu on on off asc0, wdt, ssc, interrupt detection circuitry pcd peripheral clock driver f cpu control via pcddis control via pcddis off (x)peripherals (timers, etc.) except those driven by icd, interrupt controller, ports rcd rtc clock driver f rtc on on control via pdcon / sleep- con realtime clock
c167cs derivatives parallel ports users manual 7-1 v2.0, 2000-07 7 parallel ports in order to accept or generate single external control signals or parallel data, the c167cs provides up to 111 parallel io lines organized into one 16-bit io port (port 2), eight 8-bit io ports (port0 made of p0h and p0l, port1 made of p1h and p1l, port 4, port 6, port 7, port 8), one 15-bit io port (port 3), and one 16-bit input port (port 5). these port lines may be used for general purpose input/output controlled via software or may be used implicitly by the c167css integrated peripherals or the external bus controller. all port lines are bit addressable, and all input/output lines are individually (bit-wise) programmable as inputs or outputs via direction registers (except port 5, of course). the io ports are true bidirectional ports which are switched to high impedance state when configured as inputs. the output drivers of six io ports (2, 3, 4, 6, 7, 8) can be configured (pin by pin) for push/pull operation or open-drain operation via control registers. the logic level of a pin is clocked into the input latch once per state time, regardless whether the port is configured for input or output. figure 7-1 sfrs and pins associated with the parallel ports p0l mca04460 data input / output registers direction control registers port driver control register diverse control registers p2 p4 p5 p0h p1l p1h p3 p6 p7 p8 dp0l dp2 dp4 dp0h dp1l dp1h dp3 dp6 dp7 dp8 e e e e pocon2 pocon4 pocon0h pocon1l pocon1h pocon3 e e e e pocon0l e e e e e e e pocon6 pocon7 pocon8 pocon20 e picon p1didis odp2 e odp3 e e odp4 e p5didis e odp6 e odp7 e odp8
c167cs derivatives parallel ports users manual 7-2 v2.0, 2000-07 a write operation to a port pin configured as an input causes the value to be written into the port output latch, while a read operation returns the latched state of the pin itself. a read-modify-write operation reads the value of the pin, modifies it, and writes it back to the output latch. writing to a pin configured as an output (dpx.y = 1) causes the output latch and the pin to have the written value, since the output buffer is enabled. reading this pin returns the value of the output latch. a read-modify-write operation reads the value of the output latch, modifies it, and writes it back to the output latch, thus also modifying the level at the pin. 7.1 input threshold control the standard inputs of the c167cs determine the status of input signals according to ttl levels. in order to accept and recognize noisy signals, cmos-like input thresholds can be selected instead of the standard ttl thresholds for all pins of specific ports. these special thresholds are defined above the ttl thresholds and feature a defined hysteresis to prevent the inputs from toggling while the respective input signal level is near the thresholds. the port input control register picon allows to select these thresholds for each byte of the indicated ports, i.e. 8-bit ports are controlled by one bit each while 16-bit ports are controlled by two bits each. picon port input control reg. sfr (f1c4 h /e2 h ) reset value: - - 00 h 1514131211109876543210 p8l in p7l in p6l in p4l in p3h in p3l in p2h in p2l in - - - - - - - - rw rw rw rw rw rw rw rw bit function pxlin port x low byte input level selection 0: pins px.7 px.0 switch on standard ttl input levels 1: pins px.7 px.0 switch on special threshold input levels pxhin port x high byte input level selection 0: pins px.15 px.8 switch on standard ttl input levels 1: pins px.15 px.8 switch on special threshold input levels
c167cs derivatives parallel ports users manual 7-3 v2.0, 2000-07 all options for individual direction and output mode control are available for each pin independent from the selected input threshold. the input hysteresis provides stable inputs from noisy or slowly changing external signals. figure 7-2 hysteresis for special input thresholds mct04341 bit state input level hysteresis
c167cs derivatives parallel ports users manual 7-4 v2.0, 2000-07 7.2 output driver control the output driver of a port pin is activated by switching the respective pin to output, i.e. dpx.y = 1. the value that is driven to the pin is determined by the port output latch or by the associated alternate function (e.g. address, peripheral io, etc.). the user software can control the characteristics of the output driver via the following mechanisms: ? open drain mode : the upper (push) transistor is always disabled. only 0 is driven actively, an external pullup is required. ? driver characteristic : the driver strength (static/dynamic) can be selected. ? edge characteristic : the rise/fall time of an output signal can be selected. open drain mode in the c167cs certain ports provide open drain control, which allows to switch the output driver of a port pin from a push/pull configuration to an open drain configuration. in push/pull mode a port output driver has an upper and a lower transistor, thus it can actively drive the line either to a high or a low level. in open drain mode the upper transistor is always switched off, and the output driver can only actively drive the line to a low level. when writing a 1 to the port latch, the lower transistor is switched off and the output enters a high-impedance state. the high level must then be provided by an external pullup device. with this feature, it is possible to connect several port pins together to a wired-and configuration, saving external glue logic and/or additional software overhead for enabling/disabling output signals. this feature is controlled through the respective open drain control registers odpx which are provided for each port that has this feature implemented. these registers allow the individual bit-wise selection of the open drain mode for each port line. if the respective control bit odpx.y is 0 (default after reset), the output driver is in the push/pull mode. if odpx.y is 1, the open drain configuration is selected. note that all odpx registers are located in the esfr space. figure 7-3 output drivers in push/pull mode and in open drain mode mcs01975 open drain output driver external pullup q push/pull output driver q pin pin
c167cs derivatives parallel ports users manual 7-5 v2.0, 2000-07 driver characteristic this defines either the general driving capability of the respective driver, or if the driver strength is reduced after the target output level has been reached or not. reducing the driver strength increases the outputs internal resistance which attenuates noise that is imported/exported via the output line. for driving leds or power transistors, however, a stable high output current may still be required. the controllable output drivers of the c167cs pins feature two differently sized transistors (strong and weak) for each direction (push and pull). the time of activating/ deactivating these transistors determines the output characteristics of the respective port driver. three modes can be selected to adapt the driver characteristics to the applications requirements: in high current mode both transistors are activated all the time. in this case the driver provides maximum output current even after the target signal level is reached. in low noise mode both transistors are activated at the beginning of a signal transition. when the target signal level is reached the driver strength is reduced by switching off the strong transistor. the weak transistor will keep the specified output level while the susceptibility for noise is reduced. in low current mode only the weak transistor is activated while the strong transistor remains off. this results in smooth transitions with low current peaks (and reduced susceptibility for noise) on the cost of increased transition times, i.e. slower edges, depending on the capacitive load.
c167cs derivatives parallel ports users manual 7-6 v2.0, 2000-07 edge characteristic this defines the rise/fall time for the respective output, i.e. the output transition time. slow edges reduce the peak currents that are drawn when changing the voltage level of an external capacitive load. for a bus interface, however, fast edges may still be required. edge characteristic effects the pre-driver which controls the final output driver stage. figure 7-4 structure of two-level output driver with edge control table 7-1 output transistor operation driver mode low current mode dynamic current mode high current mode output level 0 1' 0 1' 0 1' push 1) transistors 1) the upper (push) transistors are always off for output pins that operate in open drain mode. strong --- --- --- --- on weak --- on --- on --- on pull transistors strong --- --- --- on --- weak on --- on --- on --- mcd04461 push pull strong weak strong weak data signal edge control driver control open drain control control signal driver control logic driver stage pin
c167cs derivatives parallel ports users manual 7-7 v2.0, 2000-07 the port output control registers poconx provide the corresponding control bits. for each feature (edge/driver characteristic and for each port nibble) a 2-bit control field is provided (i.e. 4 bits for each port nibble). word ports consume four control nibbles each, byte ports consume two control nibbles each, where each control nibble controls 4 pins of the respective port. the general register layout shown below is valid for all pocon registers. please note that for byte ports only two pairs of bitfields are provided (see table 7-2 ). table 7-2 lists the defined pocon registers and the allocation of control bitfields and port pins. pocon* port output control reg. * esfr (f0xx h /yy h ) reset value: 0000 h 1514131211109876543210 pn3dc pn3ec pn2dc pn2ec pn1dc pn1ec pn0dc pn0ec rw rw rw rw rw rw rw rw bit function pnxec port nibble x edge characteristic (defines the output rise/fall time t rf ) 00: fast edge mode, rise/fall times depend on the drivers dimensioning. 01: reduced edge mode. 10: reserved . 11: reserved . pnxdc port nibble x driver characteristic (defines the current delivered by the output) 00: high current mode: driver always operates with maximum strength. 01: low current mode: driver always operates with reduced strength. 10: dynamic current mode: driver strength is reduced after the target level has been reached. 11: reserved .
c167cs derivatives parallel ports users manual 7-8 v2.0, 2000-07 figure 7-5 summarizes the effects of the driver characteristics: edge characteristic generally influences the output signals shape . driver characteristic influences the signal shapes susceptibility to the external capacitive load . figure 7-5 general output signal waveforms table 7-2 port output control register allocation control register location controlled pins (by poconx.y-z) notes .15-12 .11-8 .7-4 .3-0 pocon20 f0aa h / 55 h rstout clkout /fout ale wr , rd , bhe /wh no associated port pocon8 f092 h / 49 h - - - - - - p8.7-4 p8.3-0 C pocon7 f090 h / 48 h - - - - - - p7.7-4 p7.3-0 C pocon6 f08e h / 47 h - - - - - - p6.7-4 p6.3-0 C pocon4 f08c h / 46 h - - - - - - p4.7-4 p4.3-0 C pocon3 f08a h / 45 h p3.15-12 p3.11-8 p3.7-4 p3.3-0 p3.14 is missing pocon2 f088 h / 44 h p2.15-12 p2.11-8 p2.7-4 p2.3-0 C pocon1h f086 h / 43 h - - - - - - p1h.7-4 p1h.3-0 C pocon1l f084 h / 42 h - - - - - - p1l.7-4 p1l.3-0 C pocon0h f082 h / 41 h - - - - - - p0h.7-4 p0h.3-0 C pocon0l f080 h / 40 h - - - - - - p0l.7-4 p0l.3-0 C mcd04462 fast edge, high current / dynamic slow edge, high current / dynamic fast edge, low current slow edge, low current
c167cs derivatives parallel ports users manual 7-9 v2.0, 2000-07 7.3 alternate port functions in order to provide a maximum of flexibility for different applications and their specific io requirements, port lines have programmable alternate input or output functions associated with them. table 7-3 summary of alternate port functions port alternate function(s) alternate signal(s) port0 address and data lines when accessing external resources (e.g. memory) ad15 ad0 port1 address lines when accessing ext. resources, capture inputs or compare outputs of the capcom units, analog input extension channels to the a/d converter a15 a0, cc27io cc24io, an23 an16 port 2 capture inputs or compare outputs of the capcom units, capcom timer input, fast external interrupt inputs cc15io cc0io, t7in, ex7in ex0in port 3 system clock or programmable frequency output, optional bus control signal, input/output functions of serial interfaces, timers clkout/fout, bhe /wrh , rxd0, txd0, mtsr, mrst, sclk, t2in, t3in, t4in, t3eud, t3out, capin, t6out, t0in port 4 selected segment address lines in systems with more than 64 kbytes of ext. resources, can interface(s) when assigned a23 a16, can1_txd, can1_rxd, can2_txd, can2_rxd port 5 analog input channels to the a/d converter, timer control signal inputs an15 an0, t2eud, t4eud, t5in, t6in port 6 bus arbitration signals, chip select output signals breq , hlda , hold , cs4 cs0 port_7 capture inputs or compare outputs of the capcom units, pwm output signals cc31io cc28io, pout3 pout0 port 8 capture inputs or compare outputs of the capcom units, can interface(s) when assigned cc23io cc16io, can1_txd, can1_rxd, can2_txd, can2_rxd
c167cs derivatives parallel ports users manual 7-10 v2.0, 2000-07 if an alternate output function of a pin is to be used, the direction of this pin must be programmed for output (dpx.y = 1), except for some signals that are used directly after reset and are configured automatically. otherwise the pin remains in the high-impedance state and is not effected by the alternate output function. the respective port latch should hold a 1, because its output is combined with the alternate output data. x-peripherals (peripherals connected to the on-chip xbus) control their associated io pins directly via separate control lines. if an alternate input function of a pin is used, the direction of the pin must be programmed for input (dpx.y = 0) if an external device is driving the pin. the input direction is the default after reset. if no external device is connected to the pin, however, one can also set the direction for this pin to output. in this case, the pin reflects the state of the port output latch. thus, the alternate input function reads the value stored in the port output latch. this can be used for testing purposes to allow a software trigger of an alternate input function by writing to the port output latch. on most of the port lines, the user software is responsible for setting the proper direction when using an alternate input or output function of a pin. this is done by setting or clearing the direction control bit dpx.y of the pin before enabling the alternate function. there are port lines, however, where the direction of the port line is switched automatically. for instance, in the multiplexed external bus modes of port0, the direction must be switched several times for an instruction fetch in order to output the addresses and to input the data. obviously, this cannot be done through instructions. in these cases, the direction of the port line is switched automatically by hardware if the alternate function of such a pin is enabled. to determine the appropriate level of the port output latches check how the alternate data output is combined with the respective port latch output. there is one basic structure for all port lines with only an alternate input function. port lines with only an alternate output function, however, have different structures due to the way the direction of the pin is switched and depending on whether the pin is accessible by the user software or not in the alternate function mode. all port lines that are not used for these alternate functions may be used as general purpose io lines. when using port pins for general purpose output, the initial output value should be written to the port latch prior to enabling the output drivers, in order to avoid undesired transitions on the output pins. this applies to single pins as well as to pin groups (see examples below).
c167cs derivatives parallel ports users manual 7-11 v2.0, 2000-07 output_enable_single_pin: bset p4.0 ;initial output level is high bset dp4.0 ;switch on the output driver output_enable_pin_group: bfldl p4, #05h, #05h ;initial output level is high bfldl dp4, #05h, #05h ;switch on the output drivers note: when using several bset pairs to control more pins of one port, these pairs must be separated by instructions, which do not reference the respective port (see section 4.2 ). each of these ports and the alternate input and output functions are described in detail in the following subsections.
c167cs derivatives parallel ports users manual 7-12 v2.0, 2000-07 7.4 port0 the two 8-bit ports p0h and p0l represent the higher and lower part of port0, respectively. both halfs of port0 can be written (e.g. via a pec transfer) without effecting the other half. if this port is used for general purpose io, the direction of each line can be configured via the corresponding direction registers dp0h and dp0l. p0l port0 low register sfr (ff00 h /80 h ) reset value: - - 00 h 1514131211109876543210 p0l .7 p0l .6 p0l .5 p0l .4 p0l .3 p0l .2 p0l .1 p0l .0 - - - - - - - - rw rw rw rw rw rw rw rw p0h port0 high register sfr (ff02 h /81 h ) reset value: - - 00 h 1514131211109876543210 p0h .7 p0h .6 p0h .5 p0h .4 p0h .3 p0h .2 p0h .1 p0h .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function p0x.y port data register p0h or p0l bit y
c167cs derivatives parallel ports users manual 7-13 v2.0, 2000-07 alternate functions of port0 when an external bus is enabled, port0 is used as data bus or address/data bus. note that an external 8-bit demultiplexed bus only uses p0l, while p0h is free for io (provided that no other bus mode is enabled). port0 is also used to select the system startup configuration. during reset, port0 is configured to input, and each line is held high through an internal pullup device. each line can now be individually pulled to a low level (see dc-level specifications in the respective data sheets) through an external pulldown device. a default configuration is selected when the respective port0 lines are at a high level. through pulling individual lines to a low level, this default can be changed according to the needs of the applications. the internal pullup devices are designed such that an external pulldown resistors (see data sheet specification) can be used to apply a correct low level. these external pulldown resistors can remain connected to the port0 pins also during normal operation, however, care has to be taken such that they do not disturb the normal function of port0 (this might be the case, for example, if the external resistor is too strong). with the end of reset, the selected bus configuration will be written to the buscon0 register. the configuration of the high byte of port0 will be copied into the special register rp0h. this read-only register holds the selection for the number of chip selects dp0l p0l direction ctrl. register esfr (f100 h /80 h ) reset value: - - 00 h 1514131211109876543210 dp0l .7 dp0l .6 dp0l .5 dp0l .4 dp0l .3 dp0l .2 dp0l .1 dp0l .0 - - - - - - - - rw rw rw rw rw rw rw rw dp0h p0h direction ctrl. register esfr (f102 h /81 h ) reset value: - - 00 h 1514131211109876543210 dp0h .7 dp0h .6 dp0h .5 dp0h .4 dp0h .3 dp0h .2 dp0h .1 dp0h .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function dp0x.y port direction register dp0h or dp0l bit y dp0x.y = 0: port line p0x.y is an input (high-impedance) dp0x.y = 1: port line p0x.y is an output
c167cs derivatives parallel ports users manual 7-14 v2.0, 2000-07 and segment addresses. software can read this register in order to react according to the selected configuration, if required. when the reset is terminated, the internal pullup devices are switched off, and port0 will be switched to the appropriate operating mode. during external accesses in multiplexed bus modes port0 first outputs the 16-bit intra-segment address as an alternate output function. port0 is then switched to high-impedance input mode to read the incoming instruction or data. in 8-bit data bus mode, two memory cycles are required for word accesses, the first for the low byte and the second for the high byte of the word. during write cycles port0 outputs the data byte or word after outputting the address. during external accesses in demultiplexed bus modes port0 reads the incoming instruction or data word or outputs the data byte or word. figure 7-6 port0 io and alternate functions while external bus cycles are executed, port0 is controlled by the bus controller. the port direction is determined by the type of the bus cycle, the data are transferred directly from/to the bus controller hardware. the alternate output data can be the 16-bit intrasegment address or the 8/16-bit data information. while port0 is not used by the bus controller, it is controlled by its direction and output latch registers. user software must therefore be very careful when writing to port0 registers while the external bus is enabled. in most cases keeping the reset values will be the best choice. figure 7-7 shows the structure of a port0 pin. mca04344 p0h.7 p0h.6 p0h.5 p0h.4 p0h.3 p0h.2 p0h.1 p0h.0 p0l.7 p0l.6 p0l.5 p0l.4 p0l.3 p0l.2 p0l.1 p0l.0 port 0 p0h p0l alternate function general purpose input/output d7 d6 d5 d4 d3 d2 d1 d0 8-bit demux bus a) b) 16-bit demux bus d0 d1 d2 d3 d4 d5 d6 d7 d8 d9 d10 d11 d12 d13 d14 d15 a15 a14 a13 a12 a11 a10 a9 a8 ad7 ad6 ad5 ad4 ad3 ad2 ad1 ad0 8-bit mux bus c) d) ad15 ad14 ad13 ad12 ad11 ad10 ad9 ad8 ad7 ad6 ad5 ad4 ad3 ad2 ad1 ad0 16-bit mux bus
c167cs derivatives parallel ports users manual 7-15 v2.0, 2000-07 figure 7-7 block diagram of a port0 pin mcb04345 internal bus read write port output latch read write direction latch 0 1 10 0 1 driver pin input latch clock altdataout alten altdir altdatain p0h.7-0, p0l.7-0
c167cs derivatives parallel ports users manual 7-16 v2.0, 2000-07 7.5 port1 the two 8-bit ports p1h and p1l represent the higher and lower part of port1, respectively. both halfs of port1 can be written (e.g. via a pec transfer) without effecting the other half. if this port is used for general purpose io, the direction of each line can be configured via the corresponding direction registers dp1h and dp1l. p1l port1 low register sfr (ff04 h /82 h ) reset value: - - 00 h 1514131211109876543210 p1l .7 p1l 6 p1l .5 p1l .4 p1l .3 p1l .2 p1l .1 p1l .0 - - - - - - - - rw rw rw rw rw rw rw rw p1h port1 high register sfr (ff06 h /83 h ) reset value: - - 00 h 1514131211109876543210 p1h .7 p1h .6 p1h .5 p1h .4 p1h .3 p1h .2 p1h .1 p1h .0 - - - - - - - - rwh rwh rwh rwh rw rw rw rw bit function p1x.y port data register p1h or p1l bit y
c167cs derivatives parallel ports users manual 7-17 v2.0, 2000-07 alternate functions of port1 when a demultiplexed external bus is enabled, port1 is used as address bus. note that demultiplexed bus modes use port1 as a 16-bit port. otherwise all 16 port lines can be used for general purpose io. the lower eight pins of port1 (p1l.7 p1l.0) are also connected to the input multiplexer of the analog/digital converter. for pins that shall be used as analog inputs it is recommended to disable the digital input stage via register p1didis (see description below). this avoids undesired cross currents and switching noise while the (analog) input signal level is between v il and v ih . these port lines accept analog signal for the extension channels (an23 an16). the upper four pins of port1 (p1h.7 p1h.4) also serve as capture inputs or compare outputs (cc27io cc24io) for the capcom2 unit. the usage of the port lines by the capcom unit, its accessibility via software, and the precautions are the same as described for the port 2 lines. as all other capture inputs, the capture input function of pins p1h.7 p1h.4 can also be used as external interrupt inputs (sample rate 16 tcl). as a side effect, the capture input capability of these lines can also be used in the address bus mode. hereby changes of the upper address lines could be detected and dp1l p1l direction ctrl. register esfr (f104 h /82 h ) reset value: - - 00 h 1514131211109876543210 dp1 l.7 dp1 l.6 dp1 l.5 dp1 l.4 dp1 l.3 dp1 l.2 dp1 l.1 dp1 l.0 - - - - - - - - rw rw rw rw rw rw rw rw dp1h p1h direction ctrl. register esfr (f106 h /83 h ) reset value: - - 00 h 1514131211109876543210 dp1 h.7 dp1 h.6 dp1 h.5 dp1 h.4 dp1 h.3 dp1 h.2 dp1 h.1 dp1 h.0 - - - - - - - - rw rw rw rw rw rw rw rw bit function dp1x.y port direction register dp1h or dp1l bit y dp1x.y = 0: port line p1x.y is an input (high-impedance) dp1x.y = 1: port line p1x.y is an output
c167cs derivatives parallel ports users manual 7-18 v2.0, 2000-07 trigger an interrupt request in order to perform some special service routines. external capture signals can only be applied if no address output is selected for port1. during external accesses in demultiplexed bus modes port1 outputs the 16-bit intra-segment address as an alternate output function. during external accesses in multiplexed bus modes, when no buscon register selects a demultiplexed bus mode, port1 is not used and is available for general purpose io. when an external bus mode is enabled, the direction of the port pin and the loading of data into the port output latch are controlled by the bus controller hardware. the input of the port output latch is disconnected from the internal bus and is switched to the line labeled alternate data output via a multiplexer. the alternate data is the 16-bit intrasegment address. while an external bus mode is enabled, the user software should not write to the port output latch, otherwise unpredictable results may occur. when the external bus modes are disabled, the contents of the direction register last written by the user becomes active. figure 7-8 port1 io and alternate functions mca04425 p1h.7 p1h.6 p1h.5 p1h.4 p1h.3 p1h.2 p1h.1 p1h.0 p1l.7 p1l.6 p1l.5 p1l.4 p1l.3 p1l.2 p1l.1 p1l.0 port 1 p1h p1l alternate function general purpose input/output a7 a6 a5 a4 a3 a2 a1 a0 8/16-bit demux bus a) b) capcom2 inputs/outputs analog extension inputs cc24io cc25io cc26io cc27io a15 a14 a13 a12 a11 a10 a9 a8 an23 an22 an21 an20 an19 an18 an17 an16
c167cs derivatives parallel ports users manual 7-19 v2.0, 2000-07 port1 digital input control the pins of p1l may be used for both digital an analog input. by setting the respective bit in register p1didis the digital input stage of the respective p1l pin can be disconnected from the pin. this is recommended when the pin is to be used as analog input, as it reduces the current through the digital input stage and prevents it from toggling while the (analog) input level is between the digital low and high thresholds. so the consumed power and the generated noise can be reduced. after reset all digital input stages are enabled. figure 7-9 shows the structure of port1 pins. the upper 4 pins of port1 combine internal bus data and alternate data output before the port latch input. p1didis p1l digital inp. disable reg. sfr (fea4 h /52 h ) reset value: 0000 h 1514131211109876543210 p1d .7 p1d .6 p1d .5 p1d .4 p1d .3 p1d .2 p1d .1 p1d .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function p1d.y port p1l bit y digital input control 0: digital input stage connected to port line p1l.y 1: digital input stage disconnected from port line p1l.y when being read or used as alternate input this line appears as 1.
c167cs derivatives parallel ports users manual 7-20 v2.0, 2000-07 figure 7-9 block diagram of a port1 pin with address and capcom function p1h.7-4 mcd04467 internal bus read port output latch read write direction latch 01 01 ccx write 0 1 0 1 driver pin input latch clock altdataout alten altdir altdatain (pin) altdatain (latch)
c167cs derivatives parallel ports users manual 7-21 v2.0, 2000-07 figure 7-10 block diagram of a port1 pin with address function p1h.3-0 mcb04348 internal bus read write port output latch read write direction latch 0 1 10 0 1 driver pin input latch clock altdataout alten altdir = '1'
c167cs derivatives parallel ports users manual 7-22 v2.0, 2000-07 figure 7-11 block diagram of a port1 pin with address and analog input function p1l.7-0 mcd04468 internal bus read write port output latch read write direction latch 0 1 1 0 1 driver pin input latch clock altdataout alten altdir = '1' 0 analoginput diginputen channelselect
c167cs derivatives parallel ports users manual 7-23 v2.0, 2000-07 7.6 port 2 if this 16-bit port is used for general purpose io, the direction of each line can be configured via the corresponding direction register dp2. each port line can be switched into push/pull or open drain mode via the open drain control register odp2. p2 port 2 data register sfr (ffc0 h /e0 h ) reset value: 0000 h 1514131211109876543210 p2 .15 p2 .14 p2 .13 p2 .12 p2 .11 p2 .10 p2.9 p2.8 p2.7 p2.6 p2.5 p2.4 p2.3 p2.2 p2.1 p2.0 rwh rwh rwh rwh rwh rwh rwh rwh rwh rwh rwh rwh rwh rwh rwh rwh bit function p2.y port data register p2 bit y dp2 p2 direction ctrl. register sfr (ffc2 h /e1 h ) reset value: 0000 h 1514131211109876543210 dp2 .15 dp2 .14 dp2 .13 dp2 .12 dp2 .11 dp2 .10 dp2 .9 dp2 .8 dp2 .7 dp2 .6 dp2 .5 dp2 .4 dp2 .3 dp2 .2 dp2 .1 dp2 .0 rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw bit function dp2.y port direction register dp2 bit y dp2.y = 0: port line p2.y is an input (high-impedance) dp2.y = 1: port line p2.y is an output
c167cs derivatives parallel ports users manual 7-24 v2.0, 2000-07 odp2 p2 open drain ctrl. reg. esfr (f1c2 h /e1 h ) reset value: 0000 h 1514131211109876543210 odp2 .15 odp2 .14 odp2 .13 odp2 .12 odp2 .11 odp2 .10 odp2 .9 odp2 .8 odp2 .7 odp2 .6 odp2 .5 odp2 .4 odp2 .3 odp2 .2 odp2 .1 odp2 .0 rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw bit function odp2.y port 2 open drain control register bit y odp2.y = 0: port line p2.y output driver in push/pull mode odp2.y = 1: port line p2.y output driver in open drain mode
c167cs derivatives parallel ports users manual 7-25 v2.0, 2000-07 alternate functions of port 2 all port 2 lines (p2.15 p2.0) serve as capture inputs or compare outputs (cc15io cc0io) for the capcom1 unit. the upper eight port 2 lines (p2.15 p2.8) also serve as external interrupt inputs ex7in ex0in (16 tcl sample rate). when a port 2 line is used as a capture input, the state of the input latch, which represents the state of the port pin, is directed to the capcom unit via the line alternate pin data input. if an external capture trigger signal is used, the direction of the respective pin must be set to input. if the direction is set to output, the state of the port output latch will be read since the pin represents the state of the output latch. this can be used to trigger a capture event through software by setting or clearing the port latch. note that in the output configuration, no external device may drive the pin, otherwise conflicts would occur. when a port 2 line is used as a compare output (compare modes 1 and 3), the compare event (or the timer overflow in compare mode 3) directly effects the port output latch. in compare mode 1, when a valid compare match occurs, the state of the port output latch is read by the capcom control hardware via the line alternate latch data input, inverted, and written back to the latch via the line alternate data output. the port output latch is clocked by the signal compare trigger which is generated by the capcom unit. in compare mode 3, when a match occurs, the value 1 is written to the port output latch via the line alternate data output. when an overflow of the corresponding timer occurs, a 0 is written to the port output latch. in both cases, the output latch is clocked by the signal compare trigger. the direction of the pin should be set to output by the user, otherwise the pin will be in the high-impedance state and will not reflect the state of the output latch. as can be seen from the port structure below, the user software always has free access to the port pin even when it is used as a compare output. this is useful for setting up the initial level of the pin when using compare mode 1 or the double-register mode. in these modes, unlike in compare mode 3, the pin is not set to a specific value when a compare match occurs, but is toggled instead. when the user wants to write to the port pin at the same time a compare trigger tries to clock the output latch, the write operation of the user software has priority. each time a cpu write access to the port output latch occurs, the input multiplexer of the port output latch is switched to the line connected to the internal bus. the port output latch will receive the value from the internal bus and the hardware triggered change will be lost. as all other capture inputs, the capture input function of pins p2.15 p2.0 can also be used as external interrupt inputs (sample rate 16 tcl) or as fast external interrupt inputs (sample rate 2 tcl). p2.15 in addition serves as input for capcom2 timer t7 (t7in). table 7-4 summarizes the alternate functions of port 2.
c167cs derivatives parallel ports users manual 7-26 v2.0, 2000-07 figure 7-12 port 2 io and alternate functions table 7-4 alternate functions of port 2 port 2 pin alternate function a) alternate function b) alternate function c) p2.0 p2.1 p2.2 p2.3 p2.4 p2.5 p2.6 p2.7 p2.8 p2.9 p2.10 p2.11 p2.12 p2.13 p2.14 p2.15 cc0io cc1io cc2io cc3io cc4io cc5io cc6io cc7io cc8io cc9io cc10io cc11io cc12io cc13io cc14io cc15io C C C C C C C C ex0in fast external interrupt 0 inp. ex1in fast external interrupt 1 inp. ex2in fast external interrupt 2 inp. ex3in fast external interrupt 3 inp. ex4in fast external interrupt 4 inp. ex5in fast external interrupt 5 inp. ex6in fast external interrupt 6 inp. ex7in fast external interrupt 7 inp. C C C C C C C C C C C C C C C t7in timer t7 ext. count input mca04349 p2.15 p2.14 p2.13 p2.12 p2.11 p2.10 p2.9 p2.8 p2.7 p2.6 p2.5 p2.4 p2.3 p2.2 p2.1 p2.0 port 2 alternate function general purpose input/output cc7io cc6io cc5io cc4io cc3io cc2io cc1io cc0io capcom1 capt. inp./ comp. output a) cc15io cc14io cc13io cc12io cc11io cc10io cc9io cc8io ex0in ex1in ex2in ex3in ex4in ex5in ex6in ex7in b) fast external interrupt input c) capcom2 timer t7 input t7in
c167cs derivatives parallel ports users manual 7-27 v2.0, 2000-07 the pins of port 2 combine internal bus data and alternate data output before the port latch input. figure 7-13 block diagram of a port 2 pin note: fast external interrupt inputs only on the upper eight pins of port2. p2.15-0, x = 15-0, z = 7-0 mcb04350 internal bus read port output latch read write direction latch read write open drain latch 10 driver pin input latch clock altdatain (pin) 01 ccx write altdatain (latch) exzin
c167cs derivatives parallel ports users manual 7-28 v2.0, 2000-07 7.7 port 3 if this 15-bit port is used for general purpose io, the direction of each line can be configured via the corresponding direction register dp3. most port lines can be switched into push/pull or open drain mode via the open drain control register odp3 (pins p3.15 and p3.12 do not support open drain mode!). p3 port 3 data register sfr (ffc4 h /e2 h ) reset value: 0000 h 1514131211109876543210 p3 .15 - p3 .13 p3 .12 p3 .11 p3 .10 p3 .9 p3 .8 p3.7 p3.6 p3.5 p3.4 p3.3 p3.2 p3.1 p3.0 rw - rw rw rw rw rw rw rw rw rw rw rw rw rw rw bit function p3.y port data register p3 bit y dp3 p3 direction ctrl. register sfr (ffc6 h /e3 h ) reset value: 0000 h 1514131211109876543210 dp3 .15 - dp3 .13 dp3 .12 dp3 .11 dp3 .10 dp3 .9 dp3 .8 dp3 .7 dp3 .6 dp3 .5 dp3 .4 dp3 .3 dp3 .2 dp3 .1 dp3 .0 rw - rw rw rw rw rw rw rw rw rw rw rw rw rw rw bit function dp3.y port direction register dp3 bit y dp3.y = 0: port line p3.y is an input (high-impedance) dp3.y = 1: port line p3.y is an output
c167cs derivatives parallel ports users manual 7-29 v2.0, 2000-07 note: due to pin limitations register bit p3.14 is not connected to an io pin. pins p3.15 and p3.12 do not support open drain mode. alternate functions of port 3 the pins of port 3 serve for various functions which include external timer control lines, the two serial interfaces, and the control lines bhe /wrh and clock output. table 7-5 summarizes the alternate functions of port 3. odp3 p3 open drain ctrl. reg. esfr (f1c6 h /e3 h ) reset value: 0000 h 1514131211109876543210 -- odp 3.13 - odp 3.11 odp 3.10 odp 3.9 odp 3.8 odp 3.7 odp 3.6 odp 3.5 odp 3.4 odp 3.3 odp 3.2 odp 3.1 odp 3.0 - - rw - rw rw rw rw rw rw rw rw rw rw rw rw bit function odp3.y port 3 open drain control register bit y odp3.y = 0: port line p3.y output driver in push/pull mode odp3.y = 1: port line p3.y output driver in open drain mode table 7-5 alternate functions of port 3 port 3 pin alternate function p3.0 p3.1 p3.2 p3.3 p3.4 p3.5 p3.6 p3.7 p3.8 p3.9 p3.10 p3.11 p3.12 p3.13 C p3.15 t0in capcom1 timer t0 count input t6out gpt2 timer t6 toggle latch output capin gpt2 capture input t3out gpt1 timer t3 toggle latch output t3eud gpt1 timer t3 external up/down input t4in gpt1 timer t4 count input t3in gpt1 timer t3 count input t2in gpt1 timer t2 count input mrst ssc master receive/slave transmit mtsr ssc master transmit/slave receive txd0 asc0 transmit data output rxd0 asc0 receive data input bhe /wrh byte high enable/write high output sclk ssc shift clock input/output C clkout/ system clock output/ fout programmable frequency output
c167cs derivatives parallel ports users manual 7-30 v2.0, 2000-07 figure 7-14 port 3 io and alternate functions the port structure of the port 3 pins depends on their alternate function (see figure 7-15 ). when the on-chip peripheral associated with a port 3 pin is configured to use the alternate input function, it reads the input latch, which represents the state of the pin, via the line labeled alternate data input. port 3 pins with alternate input functions are: t0in, t2in, t3in, t4in, t3eud, and capin. when the on-chip peripheral associated with a port 3 pin is configured to use the alternate output function, its alternate data output line is anded with the port output latch line. when using these alternate functions, the user must set the direction of the port line to output (dp3.y = 1) and must set the port output latch (p3.y = 1). otherwise the pin is in its high-impedance state (when configured as input) or the pin is stuck at 0 (when the port output latch is cleared). when the alternate output functions are not used, the alternate data output line is in its inactive state, which is a high level (1). port 3 pins with alternate output functions are: t6out, t3out, txd0, and clkout/fout. when the on-chip peripheral associated with a port 3 pin is configured to use both the alternate input and output function, the descriptions above apply to the respective current operating mode. the direction must be set accordingly. port 3 pins with alternate input/output functions are: mtsr, mrst, rxd0, and sclk. note: enabling the clkout function automatically enables the p3.15 output driver. setting bit dp3.15 = 1 is not required. the clkout function is automatically enabled in emulation mode. mca04426 p3.15 p3.13 p3.12 p3.11 p3.10 p3.9 p3.8 p3.7 p3.6 p3.5 p3.4 p3.3 p3.2 p3.1 p3.0 port 3 no pin alternate function general purpose input/output t2in t3in t4in t3eud t3out capin t6out t0in a) b) clkout sclk bhe rxd0 txd0 mtsr mrst wrh fout
c167cs derivatives parallel ports users manual 7-31 v2.0, 2000-07 figure 7-15 block diagram of a port 3 pin with alternate input or alternate output function pin p3.12 (bhe /wrh ) is one more pin with an alternate output function. however, its structure is slightly different (see figure 7-16 ), because after reset the bhe or wrh function must be used depending on the system startup configuration. in these cases there is no possibility to program any port latches before. thus the appropriate alternate function is selected automatically. if bhe /wrh is not used in the system, this pin can be used for general purpose io by disabling the alternate function (bytdis = 1/ wrcfg = 0). p3.13, p3.11-0 mcb04352 internal bus read port output latch read write direction latch read write open drain latch 10 driver pin input latch clock altdatain write altdataout &
c167cs derivatives parallel ports users manual 7-32 v2.0, 2000-07 figure 7-16 block diagram of pins p3.15 (clkout/fout) and p3.12 (bhe /wrh ) note: enabling the bhe or wrh function automatically enables the p3.12 output driver. setting bit dp3.12 = 1 is not required. during bus hold pin bhe (if enabled) is floating. enabling the clkout function automatically enables the p3.15 output driver. setting bit dp3.15 = 1 is not required. mcb04353 internal bus read write port output latch read write direction latch 0 1 10 0 1 driver pin input latch clock altdataout alten altdir = '1' p3.15, p3.12
c167cs derivatives parallel ports users manual 7-33 v2.0, 2000-07 7.8 port 4 if this 8-bit port is used for general purpose io, the direction of each line can be configured via the corresponding direction register dp4. p4 port 4 data register sfr (ffc8 h /e4 h ) reset value: - - 00 h 1514131211109876543210 p4.7 p4.6 p4.5 p4.4 p4.3 p4.2 p4.1 p4.0 - - - - - - - - rw rw rw rw rw rw rw rw bit function p4.y port data register p4 bit y dp4 p4 direction ctrl. register sfr (ffca h /e5 h ) reset value: - - 00 h 1514131211109876543210 dp4 .7 dp4 .6 dp4 .5 dp4 .4 dp4 .3 dp4 .2 dp4 .1 dp4 .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function dp4.y port direction register dp4 bit y dp4.y = 0: port line p4.y is an input (high-impedance) dp4.y = 1: port line p4.y is an output
c167cs derivatives parallel ports users manual 7-34 v2.0, 2000-07 odp4 p4 open drain ctrl. reg. esfr (f1ca h /e5 h ) reset value: - - 00 h 1514131211109876543210 odp4 .7 odp4 .6 odp4 .5 odp4 .4 odp4 .3 odp4 .2 odp4 .1 odp4 .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function odp4.y port 4 open drain control register bit y odp4.y = 0: port line p4.y output driver in push/pull mode odp4.y = 1: port line p4.y output driver in open drain mode
c167cs derivatives parallel ports users manual 7-35 v2.0, 2000-07 alternate functions of port 4 during external bus cycles that use segmentation (i.e. an address space above 64 kbyte) a number of port 4 pins may output the segment address lines. the number of pins that is used for segment address output determines the external address space which is directly accessible. the other pins of port 4 (if any) may be used for general purpose io or for the can interface. if segment address lines are selected, the alternate function of port 4 may be necessary to access e.g. external memory directly after reset. for this reason port 4 will be switched to this alternate function automatically. the number of segment address lines is selected via bitfield salsel in register rp0h. during an external reset register rp0h is configured according to the levels of port0. software can adjust the number of selected segment address lines via register rstcon. the can interface(s) can use 2 or 4 pins of port 4 to interface the can module(s) to an external transceiver. in this case the number of possible segment address lines is reduced. table 7-6 summarizes the alternate functions of port 4 depending on the number of selected segment address lines (coded via bitfield salsel). note: port 4 pins that are neither used for segment address output nor for the can interface may be used for general purpose io. if more than one function is selected for a port 4 pin, the can interface lines will override general purpose io and the segment address. table 7-6 alternate functions of port 4 port 4 pin std. function salsel = 01 64 kb altern. function salsel = 11 256kb altern. function salsel = 00 1 mb altern. function salsel = 10 16 mb p4.0 p4.1 p4.2 p4.3 p4.4 p4.5 p4.6 p4.7 gen. purpose io gen. purpose io gen. purpose io gen. purpose io gen. p. io or can gen. p. io or can gen. p. io or can gen. p. io or can seg. address a16 seg. address a17 gen. purpose io gen. purpose io gen. p. io or can gen. p. io or can gen. p. io or can gen. p. io or can seg. address a16 seg. address a17 seg. address a18 seg. address a19 gen. p. io or can gen. p. io or can gen. p. io or can gen. p. io or can seg. address a16 seg. address a17 seg. address a18 seg. address a19 s.a. a20 or can s.a. a21 or can s.a. a22 or can s.a. a23 or can
c167cs derivatives parallel ports users manual 7-36 v2.0, 2000-07 figure 7-17 port 4 io and alternate functions note: the usage of port 4 pins (especially p4.7) for can interface lines depends on the chosen assignments for the can module(s). can interface lines will override general purpose io and segment address lines. mca04427 - - - - - - - - p4.7 p4.6 p4.5 p4.4 p4.3 p4.2 p4.1 p4.0 port 4 alternate function general purpose input/output a23 a22 a21 a20 a19 a18 a17 a16 full segment address (16 mb) a) - - - - - - - - - - - - - - - - b) can interface can2_rxd can1_rxd can1_rxd, can2_txd can1_txd, can2_txd
c167cs derivatives parallel ports users manual 7-37 v2.0, 2000-07 figure 7-18 block diagram of a port 4 pin p4.7-0 mcd04469 internal bus read port output latch read write direction latch 01 write 0 1 0 1 driver pin input latch clock altdataout alten altdir altdatain read write open drain latch
c167cs derivatives parallel ports users manual 7-38 v2.0, 2000-07 7.9 port 5 this 16-bit input port can only read data. there is no output latch and no direction register. data written to p5 will be lost. alternate functions of port 5 each line of port 5 is also connected to the input multiplexer of the analog/digital converter. all port lines can accept analog signals (anx) that can be converted by the adc. for pins that shall be used as analog inputs it is recommended to disable the digital input stage via register p5didis (see description below). this avoids undesired cross currents and switching noise while the (analog) input signal level is between v il and v ih . some pins of port 5 also serve as external gpt timer control lines. table 7-7 summarizes the alternate functions of port 5. p5 port 5 data register sfr (ffa2 h /d1 h ) reset value: xxxx h 1514131211109876543210 p5 .15 p5 .14 p5 .13 p5 .12 p5 .11 p5 .10 p5 .9 p5 .8 p5.7 p5.6 p5.5 p5.4 p5.3 p5.2 p5.1 p5.0 r r r r r r r r r r r r r r r r bit function p5.y port data register p5 bit y (read only)
c167cs derivatives parallel ports users manual 7-39 v2.0, 2000-07 figure 7-19 port 5 io and alternate functions table 7-7 alternate functions of port 5 port 5 pin alternate function a) alternate function b) p5.0 p5.1 p5.2 p5.3 p5.4 p5.5 p5.6 p5.7 p5.8 p5.9 p5.10 p5.11 p5.12 p5.13 p5.14 p5.15 analog input an0 analog input an1 analog input an2 analog input an3 analog input an4 analog input an5 analog input an6 analog input an7 analog input an8 analog input an9 analog input an10 analog input an11 analog input an12 analog input an13 analog input an14 analog input an15 C C C C C C C C C C t6eud timer 6 ext. up/down input t5eud timer 5 ext. up/down input t6in timer 6 count input t5in timer 5 count input t4eud timer 4 ext. up/down input t2eud timer 2 ext. up/down input mca04356 p5.15 p5.14 p5.13 p5.12 p5.11 p5.10 p5.9 p5.8 p5.7 p5.6 p5.5 p5.4 p5.3 p5.2 p5.1 p5.0 port 5 alternate function general purpose input an7 an6 an5 an4 an3 an2 an1 an0 a/d converter input a) an15 an14 an13 an12 an11 an10 an9 an8 t6eud t5eud t6in t5in t4eud t2eud b) timer control input
c167cs derivatives parallel ports users manual 7-40 v2.0, 2000-07 port 5 digital input control port 5 pins may be used for both digital an analog input. by setting the respective bit in register p5didis the digital input stage of the respective port 5 pin can be disconnected from the pin. this is recommended when the pin is to be used as analog input, as it reduces the current through the digital input stage and prevents it from toggling while the (analog) input level is between the digital low and high thresholds. so the consumed power and the generated noise can be reduced. after reset all digital inputs are enabled. port 5 pins have a special port structure (see figure 7-20 ), first because it is an input only port, and second because the analog input channels are directly connected to the pins rather than to the input latches. p5didis port 5 digital inp.disable reg. sfr (ffa4 h /d2 h ) reset value: 0000 h 1514131211109876543210 p5d .15 p5d .14 p5d .13 p5d .12 p5d .11 p5d .10 p5d .9 p5d .8 p5d .7 p5d .6 p5d .5 p5d .4 p5d .3 p5d .2 p5d .1 p5d .0 rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw bit function p5d.y port 5 bit y digital input control p5d.y = 0: digital input stage connected to port line p5.y p5d.y = 1: digital input stage disconnected from port line p5.y when being read or used as alternate input this line appears as 1.
c167cs derivatives parallel ports users manual 7-41 v2.0, 2000-07 figure 7-20 block diagram of a port 5 pin note: the altdatain line does not exist on all port 5 inputs. p5.15-0 mcb04357 internal bus read pin analoginput input latch clock altdatain channelselect diginputen
c167cs derivatives parallel ports users manual 7-42 v2.0, 2000-07 7.10 port 6 if this 8-bit port is used for general purpose io, the direction of each line can be configured via the corresponding direction register dp6. each port line can be switched into push/pull or open drain mode via the open drain control register odp6. p6 port 6 data register sfr (ffcc h /e6 h ) reset value: - - 00 h 1514131211109876543210 p6.7 p6.6 p6.5 p6.4 p6.3 p6.2 p6.1 p6.0 - - - - - - - - rw rw rw rw rw rw rw rw bit function p6.y port data register p6 bit y dp6 p6 direction ctrl. register sfr (ffce h /e7 h ) reset value: - - 00 h 1514131211109876543210 dp6 .7 dp6 .6 dp6 .5 dp6 .4 dp6 .3 dp6 .2 dp6 .1 dp6 .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function dp6.y port direction register dp6 bit y dp6.y = 0: port line p6.y is an input (high-impedance) dp6.y = 1: port line p6.y is an output
c167cs derivatives parallel ports users manual 7-43 v2.0, 2000-07 alternate functions of port 6 a programmable number of chip select signals (cs4 cs0) derived from the bus control registers (buscon4 buscon0) can be output on 5 pins of port 6. the other 3 pins may be used for bus arbitration to accomodate additional masters in a c167cs system. the number of chip select signals is selected via bitfield cssel in register rp0h. during an external reset register rp0h is configured according to the levels of port0. software can adjust the number of selected chip select signals via register rstcon. table 7-8 summarizes the alternate functions of port 6 depending on the number of selected chip select lines (coded via bitfield cssel). odp6 p6 open drain ctrl. reg. esfr (f1ce h /e7 h ) reset value: - - 00 h 1514131211109876543210 odp6 .7 odp6 .6 odp6 .5 odp6 .4 odp6 .3 odp6 .2 odp6 2.1 odp6 .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function odp6.y port 6 open drain control register bit y odp6.y = 0: port line p6.y output driver in push/pull mode odp6.y = 1: port line p6.y output driver in open drain mode table 7-8 alternate functions of port 6 port 6 pin altern. function cssel = 10 altern. function cssel = 01 altern. function cssel = 00 altern. function cssel = 11 p6.0 p6.1 p6.2 p6.3 p6.4 gen. purpose io gen. purpose io gen. purpose io gen. purpose io gen. purpose io chip select cs0 chip select cs1 gen. purpose io gen. purpose io gen. purpose io chip select cs0 chip select cs1 chip select cs2 gen. purpose io gen. purpose io chip select cs0 chip select cs1 chip select cs2 chip select cs3 chip select cs4 p6.5 p6.6 p6.7 hold external hold request input hlda hold acknowledge output (master mode) or input (slave mode) breq bus request output
c167cs derivatives parallel ports users manual 7-44 v2.0, 2000-07 figure 7-21 port 6 io and alternate functions the chip select lines of port 6 additionally have an internal weak pullup device. this device is switched on under the following conditions: ? always during reset for all potential cs output pins ? if the port 6 line is used as a chip select output, and the c167cs is in hold mode (invoked through hold ), and the respective pin driver is in push/pull mode (odp6.x = 0). this feature is implemented to drive the chip select lines high during reset in order to avoid multiple chip selection, and to allow another master to access the external memory via the same chip select lines (wired-and), while the c167cs is in hold mode. with odp6.x = 1 (open drain output selected), the internal pullup device will not be active during hold mode; external pullup devices must be used in this case. when entering hold mode the cs lines are actively driven high for one clock phase, then the output level is controlled by the pullup devices (if activated). after reset the cs function must be used, if selected so. in this case there is no possibility to program any port latches before. thus the alternate function (cs ) is selected automatically in this case. note: the open drain output option can only be selected via software earliest during the initialization routine; the configured chip select lines (via cssel) will be in push/ pull output driver mode directly after reset. mca04358 - - - - - - - - p6.7 p6.6 p6.5 p6.4 p6.3 p6.2 p6.1 p6.0 port 6 alternate function general purpose input/output breq hlda hold cs4 cs3 cs2 cs1 cs0 a) - - - - - - - -
c167cs derivatives parallel ports users manual 7-45 v2.0, 2000-07 figure 7-22 block diagram of port 6 pins with an alternate output function p6.7, p6.4-0 mcb04359 internal bus read write port output latch read write direction latch read write open drain latch 0 1 10 0 1 driver pin input latch clock altdataout alten altdir = '1'
c167cs derivatives parallel ports users manual 7-46 v2.0, 2000-07 the bus arbitration signals hold , hlda and breq are selected with bit hlden in register psw. when the bus arbitration signals are enabled via hlden, also these pins are switched automatically to the appropriate direction. note that the pin drivers for hlda and breq are automatically controlled, while the pin driver for hold is automatically disabled. figure 7-23 block diagram of pin p6.6 (hlda ) p6.6 mcb04360 internal bus read write port output latch read write direction latch read write open drain latch 0 1 10 0 1 driver pin input latch clock altdataout alten altdir altdatain
c167cs derivatives parallel ports users manual 7-47 v2.0, 2000-07 figure 7-24 block diagram of pin p6.5 (hold ) p6.5 mcb04361 internal bus read write port output latch read write direction latch read write open drain latch 0 1 10 driver pin input latch clock alten altdir = '0' altdatain
c167cs derivatives parallel ports users manual 7-48 v2.0, 2000-07 7.11 port 7 if this 8-bit port is used for general purpose io, the direction of each line can be configured via the corresponding direction register dp7. each port line can be switched into push/pull or open drain mode via the open drain control register odp7. p7 port 7 data register sfr (ffd0 h /e8 h ) reset value: - - 00 h 1514131211109876543210 p7.7 p7.6 p7.5 p7.4 p7.3 p7.2 p7.1 p7.0 - - - - - - - - rw rw rw rw rw rw rw rw bit function p7.y port data register p7 bit y dp7 p7 direction ctrl. register sfr (ffd2 h /e9 h ) reset value: - - 00 h 1514131211109876543210 dp7 .7 dp7 .6 dp7 .5 dp7 .4 dp7 .3 dp7 .2 dp7 .1 dp7 .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function dp7.y port direction register dp7 bit y dp7.y = 0: port line p7.y is an input (high-impedance) dp7.y = 1: port line p7.y is an output
c167cs derivatives parallel ports users manual 7-49 v2.0, 2000-07 alternate functions of port 7 the upper four lines of port 7 (p7.7-4) serve as capture inputs or compare outputs (cc31io cc28io) for the capcom2 unit. the usage of the port lines by the capcom unit, its accessibility via software, and the precautions are the same as described for the port 2 lines. as all other capture inputs, the capture input function of pins p7.7-4 can also be used as external interrupt inputs (sample rate 16 tcl). the lower 4 lines of port 7 (p7.3-0) serve as outputs from the pwm module (pout3 pout0). at these pins the value of the respective port output latch is xored with the value of the pwm output rather than anded, as the other pins do. this allows to use the alternate output value either as it is (port latch holds a 0) or invert its level at the pin (port latch holds a 1). note that the pwm outputs must be enabled via the respective penx bits in pwmcon1. table 7-9 summarizes the alternate functions of port 7. odp7 p7 open drain ctrl. reg. esfr (f1d2 h /e9 h ) reset value: - - 00 h 1514131211109876543210 odp7 .7 odp7 .6 odp7 .5 odp7 .4 odp7 .3 odp7 .2 odp7 2.1 odp7 .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function odp7.y port 7 open drain control register bit y odp7.y = 0: port line p7.y output driver in push/pull mode odp7.y = 1: port line p7.y output driver in open drain mode table 7-9 alternate functions of port 7 port 7 pin alternate function p7.0 p7.1 p7.2 p7.3 p7.4 p7.5 p7.6 p7.7 pout0 pwm model channel 0 output pout1 pwm model channel 1 output pout2 pwm model channel 2 output pout3 pwm model channel 3 output cc28io capture input/compare output channel 28 cc29io capture input/compare output channel 29 cc30io capture input/compare output channel 30 cc31io capture input/compare output channel 31
c167cs derivatives parallel ports users manual 7-50 v2.0, 2000-07 figure 7-25 port 7 io and alternate functions the port structures of port 7 differ in the way the output latches are connected to the internal bus and to the pin driver (see figure 7-26 and figure 7-27 ). pins p7.3-0 (pout3 pout0) of port 7 xor the alternate data output with the port latch output, which allows to use the alternate data directly or inverted at the pin driver. mca04362 - - - - - - - - p7.7 p7.6 p7.5 p7.4 p7.3 p7.2 p7.1 p7.0 port 7 alternate function general purpose input/output - - - - - - - - cc31io cc30io cc29io cc28io pout3 pout2 pout1 pout0
c167cs derivatives parallel ports users manual 7-51 v2.0, 2000-07 figure 7-26 block diagram of port 7 pins p7.3-0 mcb04363 internal bus read write port output latch read write direction latch read write open drain latch 10 xor driver pin input latch clock altdataout p7.3-0
c167cs derivatives parallel ports users manual 7-52 v2.0, 2000-07 pins p7.7-4 of port 7 combine internal bus data and alternate data output before the port latch input, as do the port 2 pins. figure 7-27 block diagram of port 7 pins p7.7-4 p7.7-4 mcb04364 internal bus read port output latch read write direction latch read write open drain latch 10 driver pin input latch clock altdatain (pin) 01 ccx write altdatain (latch)
c167cs derivatives parallel ports users manual 7-53 v2.0, 2000-07 7.12 port 8 if this 8-bit port is used for general purpose io, the direction of each line can be configured via the corresponding direction register dp8. each port line can be switched into push/pull or open drain mode via the open drain control register odp8. p8 port 8 data register sfr (ffd4 h /ea h ) reset value: - - 00 h 1514131211109876543210 p8.7 p8.6 p8.5 p8.4 p8.3 p8.2 p8.1 p8.0 - - - - - - - - rwh rwh rwh rwh rwh rwh rwh rwh bit function p8.y port data register p8 bit y dp8 p8 direction ctrl. register sfr (ffd6 h /eb h ) reset value: - - 00 h 1514131211109876543210 dp8 .7 dp8 .6 dp8 .5 dp8 .4 dp8 .3 dp8 .2 dp8 .1 dp8 .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function dp8.y port direction register dp8 bit y dp8.y = 0: port line p8.y is an input (high-impedance) dp8.y = 1: port line p8.y is an output
c167cs derivatives parallel ports users manual 7-54 v2.0, 2000-07 alternate functions of port 8 all port 8 lines (p8.7-0) serve as capture inputs or compare outputs (cc23io cc16io) for the capcom2 unit (see table 7-10 ). the usage of the port lines by the capcom unit, its accessibility via software and the precautions are the same as described for the port 2 lines. as all other capture inputs, the capture input function of pins p8.7-0 can also be used as external interrupt inputs (sample rate 16 tcl). the can interface(s) can use 2 or 4 pins of port 8 to interface the can module(s) to an external transceiver. in this case the number of possible capcom io lines is reduced. note: can interface lines will override general purpose io and capcom lines. odp8 p8 open drain ctrl. reg. esfr (f1d6 h /eb h ) reset value: - - 00 h 1514131211109876543210 odp8 .7 odp8 .6 odp8 .5 odp8 .4 odp8 .3 odp8 .2 odp8 .1 odp8 .0 - - - - - - - - rw rw rw rw rw rw rw rw bit function odp8.y port 8 open drain control register bit y odp8.y = 0: port line p8.y output driver in push/pull mode odp8.y = 1: port line p8.y output driver in open drain mode table 7-10 alternate functions of port 8 port 8 pin alternate function p8.0 p8.1 p8.2 p8.3 p8.4 p8.5 p8.6 p8.7 cc16io capture input/compare output channel 16 or can cc17io capture input/compare output channel 17 or can cc18io capture input/compare output channel 18 or can cc19io capture input/compare output channel 19 or can cc20io capture input/compare output channel 20 cc21io capture input/compare output channel 21 cc22io capture input/compare output channel 22 cc23io capture input/compare output channel 23
c167cs derivatives parallel ports users manual 7-55 v2.0, 2000-07 figure 7-28 port 8 io and alternate functions mca04429 - - - - - - - - p8.7 p8.6 p8.5 p8.4 p8.3 p8.2 p8.1 p8.0 port 8 alternate function general purpose input/output a) - - - - - - - - cc23io cc22io cc21io cc20io cc19io cc18io cc17io cc16io capcom input/output b) - - - - - - - - can1_txd, can2_txd can interface can1_rxd, can2_rxd can1_txd, can2_txd can1_rxd, can2_rxd
c167cs derivatives parallel ports users manual 7-56 v2.0, 2000-07 the pins of port 8 combine internal bus data and alternate data output before the port latch input, as do the port 2 pins. figure 7-29 block diagram of port 8 pins with alternate capcom io function mcb04366 internal bus read port output latch read write direction latch read write open drain latch 10 driver pin input latch clock altdatain (pin) 01 ccx write altdatain (latch) p8.7-4
c167cs derivatives parallel ports users manual 7-57 v2.0, 2000-07 figure 7-30 block diagram of port 8 pins with alternate capcom io and can interface function mcb04430 internal bus read write port output latch read write direction latch 0 1 10 0 1 driver pin input latch clock altdataout alten altdir altdatain (pin) read write open drain latch 01 ccx altdatain (latch) p8.3-0
c167cs derivatives dedicated pins users manual 8-1 v2.0, 2000-07 8 dedicated pins most of the input/output or control signals of the functional the c167cs are realized as alternate functions of pins of the parallel ports. there is, however, a number of signals that use separate pins, including the oscillator, special control signals and, of course, the power supply. table 8-1 summarizes the 33 dedicated pins of the c167cs. the address latch enable signal ale controls external address latches that provide a stable address in multiplexed bus modes. ale is activated for every external bus cycle independent of the selected bus mode, i.e. it is also activated for bus cycles with a demultiplexed address bus. when an external bus is enabled (one or more of the busact bits set) also x-peripheral accesses will generate an active ale signal. ale is not activated for internal accesses, i.e. accesses to rom/otp/flash (if provided), the internal ram and the special function registers. in single chip mode, i.e. when no external bus is enabled (no busact bit set), ale will also remain inactive for x-peripheral accesses. during reset an internal pulldown ensures an inactive (low) level on the ale output. table 8-1 c167cs dedicated pins pin(s) function ale address latch enable rd external read strobe wr /wrl external write/write low strobe ready ready input ea external access enable nmi non-maskable interrupt input xtal1, xtal2 oscillator input/output rstin reset input rstout reset output varef, vagnd power supply for analog/digital converter vdd digital power supply (10 pins) vss digital reference ground (10 pins) nc not connected pin. should not be connected to the pcb.
c167cs derivatives dedicated pins users manual 8-2 v2.0, 2000-07 at the end of a true single-chip mode reset (ea = 1) the current level on pin ale is latched and is used for configuration (together with pin rd ). pin ale selects standard start/boot, when driven low (default) or alternate start/boot when driven high. for standard configuration pin ale should be low or not connected. the external read strobe rd controls the output drivers of external memory or peripherals when the c167cs reads data from these external devices. during accesses to on-chip x-peripherals rd remains inactive (high). during reset an internal pullup ensures an inactive (high) level on the rd output. at the end of reset the current level on pin rd is latched and is used for configuration. for a reset with external access (ea = 0) pin rd controls the oscillator watchdog. the latched rd level determines the reset value of bit owddis in register syscon. the default high level on pin rd leaves the oscillator watchdog active (owddis = 0), while a low level disables the watchdog (owddis = 1) e.g. for testing purposes. for a true single-chip mode reset (ea = 1) pin rd enables the bootstrap loader, when driven low (pin ale is evaluated together with pin rd ). for standard configuration pin rd should be high or not connected. the external write strobe wr /wrl controls the data transfer from the c167cs to an external memory or peripheral device. this pin may either provide an general wr signal activated for both byte and word write accesses, or specifically control the low byte of an external 16-bit device (wrl ) together with the signal wrh (alternate function of p3.12/ bhe ). during accesses to on-chip x-peripherals wr /wrl remains inactive (high). during reset an internal pullup ensures an inactive (high) level on the wr /wrl output. the ready input ready receives a control signal from an external memory or peripheral device that is used to terminate an external bus cycle, provided that this function is enabled for the current bus cycle. ready may be used as synchronous ready or may be evaluated asynchronously. when waitstates are defined for a ready controlled address window the ready input is not evaluated during these waitstates. an internal pullup ensures an inactive (high) level on the ready input. the external access enable pin ea determines if the c167cs after reset starts fetching code from the internal rom area (ea = 1) or via the external bus interface (ea = 0). be sure to hold this input low for romless devices. at the end of the internal reset sequence the ea signal is latched together with the configuration (port0, rd , ale). the non-maskable interrupt input nmi allows to trigger a high priority trap via an external signal (e.g. a power-fail signal). it also serves to validate the pwrdn instruction that switches the c167cs into power-down mode. the nmi pin is sampled with every cpu clock cycle to detect transitions.
c167cs derivatives dedicated pins users manual 8-3 v2.0, 2000-07 the oscillator input xtal1 and output xtal2 connect the internal main oscillator to the external crystal. the oscillator provides an inverter and a feedback element. the standard external oscillator circuitry (see chapter 6 ) comprises the crystal, two low end capacitors and series resistor to limit the current through the crystal. the main oscillator is intended for the generation of the basic operating clock signal of the c167cs. an external clock signal may be fed to the input xtal1, leaving xtal2 open or terminating it for higher input frequencies. the reset input rstin allows to put the c167cs into the well defined reset condition either at power-up or external events like a hardware failure or manual reset. the input voltage threshold of the rstin pin is raised compared to the standard pins in order to minimize the noise sensitivity of the reset input. in bidirectional reset mode the c167css line rstin may be driven active by the chip logic e.g. in order to support external equipment which is required for startup (e.g. flash memory). bidirectional reset reflects internal reset sources (software, watchdog) also to the rstin pin and converts short hardware reset pulses to a minimum duration of the internal reset sequence. bidirectional reset is enabled by setting bit bdrsten in register syscon and changes rstin from a pure input to an open drain io line. when an internal reset is triggered by the srst instruction or by a watchdog timer overflow or a low level is applied to the rstin line, an internal driver pulls it low for the duration of the internal reset sequence. after that it is released and is then controlled by the external circuitry alone. the bidirectional reset function is useful in applications where external devices require a defined reset signal but cannot be connected to the c167css rstout signal, e.g. an external flash memory which must come out of reset and deliver code well before rstout can be deactivated via einit. the following behavior differences must be observed when using the bidirectional reset feature in an application: ? bit bdrsten in register syscon cannot be changed after einit and is cleared automatically after a reset. ? the reset indication flags always indicate a long hardware reset. ? the port0 configuration is treated like on a hardware reset. especially the bootstrap loader may be activated when p0l.4 is low. ? pin rstin may only be connected to external reset devices with an open drain output driver. ? a short hardware reset is extended to the duration of the internal reset sequence.
c167cs derivatives dedicated pins users manual 8-4 v2.0, 2000-07 the reset output rstout provides a special reset signal for external circuitry. rstout is activated at the beginning of the reset sequence, triggered via rstin , a watchdog timer overflow or by the srst instruction. rstout remains active (low) until the einit instruction is executed. this allows to initialize the controller before the external circuitry is activated. note: during emulation mode pin rstout is used as an input and therefore must be driven by the external circuitry. the power supply pins for the analog/digital converter varef and vagnd provide a separate power supply (reference voltage) for the on-chip adc. this reduces the noise that is coupled to the analog input signals from the digital logic sections and so improves the stability of the conversion results, when varef and vagnd are properly discoupled from vdd and vss. the power supply pins vdd and vss provide the power supply for the digital logic of the c167cs. the respective vdd/vss pairs should be decoupled as close to the pins as possible. for best results it is recommended to implement two-level decoupling, e.g. (the widely used) 100 nf in parallel with 30 40 pf capacitors which deliver the peak currents. note: all vdd pins and all vss pins must be connected to the power supply and ground, respectively.
c167cs derivatives the external bus interface users manual 9-1 v2.0, 2000-07 9 the external bus interface although the c167cs provides a powerful set of on-chip peripherals and on-chip ram and rom/otp/flash (except for romless versions) areas, these internal units only cover a small fraction of its address space of up to 16 mbyte. the external bus interface allows to access external peripherals and additional volatile and non-volatile memory. the external bus interface provides a number of configurations, so it can be tailored to fit perfectly into a given application system. figure 9-1 sfrs and port pins associated with the external bus interface accesses to external memory or peripherals are executed by the integrated external bus controller (ebc). the function of the ebc is controlled via the syscon register and the busconx and addrselx registers. the busconx registers specify the external bus cycles in terms of address (mux/demux), data width (16-bit/8-bit), chip selects and length (waitstates/ready control/ale/rw delay). these parameters are used for accesses within a specific address area which is defined via the corresponding register addrselx. the four pairs buscon1/addrsel1 buscon4/addrsel4 allow to define four independent address windows, while all external accesses outside these windows are controlled via register buscon0. mca04367 p0l / p0h p1l / p1h dp3 addrsel1 addrsel2 addrsel3 buscon0 syscon ports & direction control alternate functions address registers mode registers control registers p0l/p0h port0 data register p1l/p1h port1 data register dp3 port 3 direction control register p3 port 3 data register p4 port 4 data register odp6 port 6 open drain control register dp6 port 6 direction control register p6 port 6 data register addrselx address range select register 1...4 busconx bus mode control register 0...4 syscon system control register rp0h port p0h reset configuration register rp0h port0 ea port1 rstin ale ready rd wr/wrl bhe/wrh p3 buscon1 buscon3 buscon2 e p4 odp6 dp6 p6 addrsel4 buscon4
c167cs derivatives the external bus interface users manual 9-2 v2.0, 2000-07 9.1 single chip mode single chip mode is entered, when pin ea is high during reset. in this case register buscon0 is initialized with 00c0 h , which also resets bit busact0, so no external bus is enabled. in single chip mode the c167cs operates only with and out of internal resources. no external bus is configured and no external peripherals and/or memory can be accessed. also no port lines are occupied for the bus interface. when running in single chip mode, however, external access may be enabled by configuring an external bus under software control. single chip mode allows the c167cs to start execution out of the internal program memory (mask-rom, otp or flash memory). note: any attempt to access a location in the external memory space in single chip mode results in the hardware trap illbus if no external bus has been explicitly enabled by software.
c167cs derivatives the external bus interface users manual 9-3 v2.0, 2000-07 9.2 external bus modes when the external bus interface is enabled (bit busactx = 1) and configured (bitfield btyp), the c167cs uses a subset of its port lines together with some control lines to build the external bus. the bus configuration (btyp) for the address windows (buscon4 buscon1) is selected via software typically during the initialization of the system. the bus configuration (btyp) for the default address range (buscon0) is selected via port0 during reset, provided that pin ea is low during reset. otherwise buscon0 may be programmed via software just like the other buscon registers. the 16 mbyte address space of the c167cs is divided into 256 segments of 64 kbyte each. the 16-bit intra-segment address is output on port0 for multiplexed bus modes or on port1 for demultiplexed bus modes. when segmentation is disabled, only one 64 kbyte segment can be used and accessed. otherwise additional address lines may be output on port 4 (addressing up to 16 mbyte) and/or several chip select lines may be used to select different memory banks or peripherals. these functions are selected during reset via bitfields salsel and cssel of register rp0h, respectively. note: bit sgtdis of register syscon defines, if the csp register is saved during interrupt entry (segmentation active) or not (segmentation disabled). table 9-1 summary of external bus modes btyp encoding external data bus width external address bus mode 0 0 8-bit data demultiplexed addresses 0 1 8-bit data multiplexed addresses 1 0 16-bit data demultiplexed addresses 1 1 16-bit data multiplexed addresses
c167cs derivatives the external bus interface users manual 9-4 v2.0, 2000-07 multiplexed bus modes in the multiplexed bus modes the 16-bit intra-segment address as well as the data use port0. the address is time-multiplexed with the data and has to be latched externally. the width of the required latch depends on the selected data bus width, i.e. an 8-bit data bus requires a byte latch (the address bits a15 a8 on p0h do not change, while p0l multiplexes address and data), a 16-bit data bus requires a word latch (the least significant address line a0 is not relevant for word accesses). the upper address lines (an a16) are permanently output on port 4 (if segmentation is enabled) and do not require latches. the ebc initiates an external access by generating the address latch enable signal (ale) and then placing an address on the bus. the falling edge of ale triggers an external latch to capture the address. after a period of time during which the address must have been latched externally, the address is removed from the bus. the ebc now activates the respective command signal (rd , wr , wrl , wrh ). data is driven onto the bus either by the ebc (for write cycles) or by the external memory/peripheral (for read cycles). after a period of time, which is determined by the access time of the memory/ peripheral, data become valid. read cycles: input data is latched and the command signal is now deactivated. this causes the accessed device to remove its data from the bus which is then tri-stated again. write cycles: the command signal is now deactivated. the data remain valid on the bus until the next external bus cycle is started. figure 9-2 multiplexed bus cycle mct02060 address segment (p4) ale bus (p0) data/instr. address rd address data bus (p0) wr bus cycle
c167cs derivatives the external bus interface users manual 9-5 v2.0, 2000-07 demultiplexed bus modes in the demultiplexed bus modes the 16-bit intra-segment address is permanently output on port1, while the data uses port0 (16-bit data) or p0l (8-bit data). the upper address lines are permanently output on port 4 (if selected via salsel during reset). no address latches are required. the ebc initiates an external access by placing an address on the address bus. after a programmable period of time the ebc activates the respective command signal (rd , wr , wrl , wrh ). data is driven onto the data bus either by the ebc (for write cycles) or by the external memory/peripheral (for read cycles). after a period of time, which is determined by the access time of the memory/peripheral, data become valid. read cycles: input data is latched and the command signal is now deactivated. this causes the accessed device to remove its data from the data bus which is then tri-stated again. write cycles: the command signal is now deactivated. if a subsequent external bus cycle is required, the ebc places the respective address on the address bus. the data remain valid on the bus until the next external bus cycle is started. figure 9-3 demultiplexed bus cycle mcd02061 address address (p1) ale bus (p0) rd data bus (p0) wr segment (p4) bus cycle data/instr.
c167cs derivatives the external bus interface users manual 9-6 v2.0, 2000-07 switching between the bus modes the ebc allows to switch between different bus modes dynamically, i.e. subsequent external bus cycles may be executed in different ways. certain address areas may use multiplexed or demultiplexed buses or use ready control or predefined waitstates. a change of the external bus characteristics can be initiated in two different ways: switching between predefined address windows automatically selects the bus mode that is associated with the respective window. predefined address windows allow to use different bus modes without any overhead, but restrict their number to the number of buscons. however, as buscon0 controls all address areas, which are not covered by the other buscons, this allows to have gaps between these windows, which use the bus mode of buscon0. port1 will output the intra-segment address, when any of the buscon registers selects a demultiplexed bus mode, even if the current bus cycle uses a multiplexed bus mode. this allows to have an external address decoder connected to port1 only, while using it for all kinds of bus cycles. the usage of the buscon/addrsel registers is controlled via the issued addresses. when an access (code fetch or data) is initiated, the respective generated physical address defines, if the access is made internally, uses one of the address windows defined by addrsel4 1, or uses the default configuration in buscon0. after initializing the active registers, they are selected and evaluated automatically by interpreting the physical address. no additional switching or selecting is necessary during run time, except when more than the four address windows plus the default is to be used. reprogramming the buscon and/or addrsel registers allows to either change the bus mode for a given address window, or change the size of an address window that uses a certain bus mode. reprogramming allows to use a great number of different address windows (more than buscons are available) on the expense of the overhead for changing the registers and keeping appropriate tables. note: be careful when changing the configuration for an address area that currently supplies the instruction stream. due to the internal pipelining, the first instruction fetch that will use the new configuration depends on the instructions prior to the configuration change. special care is required when changing bits like busact or rdyen, in order not to cut the instruction stream inadvertently. only change the other configuration bits after checking that the respective application can cope with the intended modification(s). it is recommended to change addrsel registers only while the respective busact bit in the associated buscon register is cleared. switching from demultiplexed to multiplexed bus mode represents a special case. the bus cycle is started by activating ale and driving the address to port 4 and port1 as usual, if another buscon register selects a demultiplexed bus. however, in the
c167cs derivatives the external bus interface users manual 9-7 v2.0, 2000-07 multiplexed bus modes the address is also required on port0. in this special case the address on port0 is delayed by one cpu clock cycle, which delays the complete (multiplexed) bus cycle and extends the corresponding ale signal (see figure 9-4 ). this extra time is required to allow the previously selected device (via demultiplexed bus) to release the data bus, which would be available in a demultiplexed bus cycle. figure 9-4 switching from demultiplexed to multiplexed bus mode switching between external resources (e.g. different peripherals) may incur a problem if the previously accessed resource needs some time to switch of its output drivers (after a read) and the resource to be accessed next switches on its output drivers very fast. in systems running on higher frequencies this may lead to a bus conflict (the switch off delays normally are independent from the clock frequency). in such a case an additional waitstate can automatically be inserted when leaving a certain address window, i.e. when the next cycle accesses a different window. this waitstate is controlled in the same way as the waitstate when switching from demultiplexed to multiplexed bus mode, see figure 9-4 . buscon switch waitstates are enabled via bits bswcx in the buscon registers. by enabling the automatic buscon switch waitstate (bswcx = 1) there is no impact on the system performance as long as the external bus cycles access the same address window. only if the following cycle accesses a different window a waitstate is inserted between the last access to the previous window and the first access to the new window. after reset no buscon switch waitstates are selected. mcd02234 address data/instr. address address data bus cycle address address (p1) ale rd data wr segment (p4) bus cycle bus (p0) bus (p0) demultiplexed multiplexed idle state data/instr.
c167cs derivatives the external bus interface users manual 9-8 v2.0, 2000-07 external data bus width the ebc can operate on 8-bit or 16-bit wide external memory/peripherals. a 16-bit data bus uses port0, while an 8-bit data bus only uses p0l, the lower byte of port0. this saves on address latches, bus transceivers, bus routing and memory cost on the expense of transfer time. the ebc can control word accesses on an 8-bit data bus as well as byte accesses on a 16-bit data bus. word accesses on an 8-bit data bus are automatically split into two subsequent byte accesses, where the low byte is accessed first, then the high byte. the assembly of bytes to words and the disassembly of words into bytes is handled by the ebc and is transparent to the cpu and the programmer. byte accesses on a 16-bit data bus require that the upper and lower half of the memory can be accessed individually. in this case the upper byte is selected with the bhe signal, while the lower byte is selected with the a0 signal. so the two bytes of the memory can be enabled independent from each other, or together when accessing words. when writing bytes to an external 16-bit device, which has a single cs input, but two wr enable inputs (for the two bytes), the ebc can directly generate these two write control signals. this saves the external combination of the wr signal with a0 or bhe . in this case pin wr serves as wrl (write low byte) and pin bhe serves as wrh (write high byte). bit wrcfg in register syscon selects the operating mode for pins wr and bhe . the respective byte will be written on both data bus halfs. when reading bytes from an external 16-bit device, whole words may be read and the c167cs automatically selects the byte to be input and discards the other. however, care must be taken when reading devices that change state when being read, like fifos, interrupt status registers, etc. in this case individual bytes should be selected using bhe and a0. note: port1 becomes available for general purpose io, when none of the buscon registers selects a demultiplexed bus mode. table 9-2 bus mode versus performance bus mode transfer rate (speed factor for byte/word/dword access) system requirements free io lines 8-bit multiplexed very low (1.5/3/6) low (8-bit latch, byte bus) p1h, p1l 8-bit demultipl. low (1/2/4) very low (no latch, byte bus) p0h 16-bit multiplexed high (1.5/1.5/3) high (16-bit latch, word bus) p1h, p1l 16-bit demultipl. very high (1/1/2) low (no latch, word bus) C
c167cs derivatives the external bus interface users manual 9-9 v2.0, 2000-07 disable/enable control for pin bhe ( bytdis) bit bytdis is provided for controlling the active low byte high enable (bhe ) pin. the function of the bhe pin is enabled, if the bytdis bit contains a 0. otherwise, it is disabled and the pin can be used as standard io pin. the bhe pin is implicitly used by the external bus controller to select one of two byte-organized memory chips, which are connected to the c167cs via a word-wide external data bus. after reset the bhe function is automatically enabled (bytdis = 0), if a 16-bit data bus is selected during reset, otherwise it is disabled (bytdis = 1). it may be disabled, if byte access to 16-bit memory is not required, and the bhe signal is not used. segment address generation during external accesses the ebc generates a (programmable) number of address lines on port 4, which extend the 16-bit address output on port0 or port1 and so increase the accessible address space. the number of segment address lines is selected during reset and coded in bit field salsel in register rp0 h (see table 9-3 ). note: the total accessible address space may be increased by accessing several banks which are distinguished by individual chip select lines. if port 4 is used to output segment address lines, in most cases the drivers must operate in push/pull mode. make sure that opd4 does not select open drain mode in this case. table 9-3 decoding of segment address lines salsel segment address lines directly accessible address space 1 1 two: a17 a16 256 kbyte (default without pull-downs) 1 0 eight: a23 a16 16 mbyte (maximum) 0 1 none 64 kbyte (minimum) 0 0 four: a19 a16 1 mbyte
c167cs derivatives the external bus interface users manual 9-10 v2.0, 2000-07 cs signal generation during external accesses the ebc can generate a (programmable) number of cs lines on port 6, which allow to directly select external peripherals or memory banks without requiring an external decoder. the number of cs lines is selected during reset and coded in bit field cssel in register rp0h (see table 9-4 ). the csx outputs are associated with the busconx registers and are driven active (low) for any access within the address area defined for the respective buscon register. for any access outside this defined address area the respective csx signal will go inactive (high). at the beginning of each external bus cycle the corresponding valid cs signal is determined and activated. all other cs lines are deactivated (driven high) at the same time. note: the csx signals will not be updated for an access to any internal address area (i.e. when no external bus cycle is started), even if this area is covered by the respective addrselx register. an access to an on-chip x-peripheral deactivates all external cs signals. upon accesses to address windows without a selected cs line all selected cs lines are deactivated. the chip select signals allow to be operated in four different modes (see table 9-5 ) which are selected via bits cswenx and csrenx in the respective busconx register. table 9-4 decoding of chip select lines cssel chip select lines note 1 1 five: cs4 cs0 default without pull-downs 1 0 none port 6 pins free for io 0 1 two: cs1 cs0 C 0 0 three: cs2 cs0 C table 9-5 chip select generation modes cswenx csrenx chip select mode 0 0 address chip select (default after reset) 0 1 read chip select 1 0 write chip select 1 1 read/write chip select
c167cs derivatives the external bus interface users manual 9-11 v2.0, 2000-07 read or write chip select signals remain active only as long as the associated control signal (rd or wr ) is active. this also includes the programmable read/write delay. read chip select is only activated for read cycles, write chip select is only activated for write cycles, read/write chip select is activated for both read and write cycles (write cycles are assumed, if any of the signals wrh or wrl gets active). these modes save external glue logic, when accessing external devices like latches or drivers that only provide a single enable input. address chip select signals remain active during the complete bus cycle. for address chip select signals two generation modes can be selected via bit cscfg in register syscon: ?a latched address chip select signal (cscfg = 0) becomes active with the falling edge of ale and becomes inactive at the beginning of an external bus cycle that accesses a different address window. no spikes will be generated on the chip select lines and no changes occur as long as locations within the same address window or within internal memory (excluding x-peripherals and xram) are accessed. ?an early address chip select signal (cscfg = 1) becomes active together with the address and bhe (if enabled) and remains active until the end of the current bus cycle. early address chip select signals are not latched internally and may toggle intermediately while the address is changing. note: cs0 provides a latched address chip select directly after reset (except for single chip mode) when the first instruction is fetched. internal pullup devices hold all cs lines high during reset. after the end of a reset sequence the pullup devices are switched off and the pin drivers control the pin levels on the selected cs lines. not selected cs lines will enter the high-impedance state and are available for general purpose io. the pullup devices are also active during bus hold on the selected cs lines, while hlda is active and the respective pin is switched to push/pull mode. open drain outputs will float during bus hold. in this case external pullup devices are required or the new bus master is responsible for driving appropriate levels on the cs lines. segment address versus chip select the external bus interface of the c167cs supports many configurations for the external memory. by increasing the number of segment address lines the c167cs can address a linear address space of 256 kbyte, 1 mbyte or 16 mbyte. this allows to implement a large sequential memory area, and also allows to access a great number of external devices, using an external decoder. by increasing the number of cs lines the c167cs can access memory banks or peripherals without external glue logic. these two features may be combined to optimize the overall system performance. note: bit sgtdis of register syscon defines, if the csp register is saved during interrupt entry (segmentation active) or not (segmentation disabled).
c167cs derivatives the external bus interface users manual 9-12 v2.0, 2000-07 9.3 programmable bus characteristics important timing characteristics of the external bus interface have been made user programmable to allow to adapt it to a wide range of different external bus and memory configurations with different types of memories and/or peripherals. the following parameters of an external bus cycle are programmable: ? ale control defines the ale signal length and the address hold time after its falling edge ? memory cycle time (extendable with 1 15 waitstates) defines the allowable access time ? memory tri-state time (extendable with 1 waitstate) defines the time for a data driver to float ? read/write delay time defines when a command is activated after the falling edge of ale ? ready control defines, if a bus cycle is terminated internally or externally note: internal accesses are executed with maximum speed and therefore are not programmable. external accesses use the slowest possible bus cycle after reset. the bus cycle timing may then be optimized by the initialization software. figure 9-5 programmable external bus cycle rd/wr data addr ale alectl data rd/wr addr ale mttc mctc mcd02225
c167cs derivatives the external bus interface users manual 9-13 v2.0, 2000-07 ale length control the length of the ale signal and the address hold time after its falling edge are controlled by the alectlx bits in the buscon registers. when bit alectl is set to 1, external bus cycles accessing the respective address window will have their ale signal prolonged by half a cpu clock (1 tcl). also the address hold time after the falling edge of ale (on a multiplexed bus) will be prolonged by half a cpu clock, so the data transfer within a bus cycle refers to the same clkout edges as usual (i.e. the data transfer is delayed by one cpu clock). this allows more time for the address to be latched. note: alectl0 is 1 after reset to select the slowest possible bus cycle, the other alectlx are 0 after reset. figure 9-6 ale length control setup (p0) wr bus address data (p0) bus rd (p4) ale segment normal multiplexed bus cycle address address data/instr. address data mcd02235 lengthened multiplexed bus cycle address address hold data/instr.
c167cs derivatives the external bus interface users manual 9-14 v2.0, 2000-07 programmable memory cycle time the c167cs allows the user to adjust the controllers external bus cycles to the access time of the respective memory or peripheral. this access time is the total time required to move the data to the destination. it represents the period of time during which the controllers signals do not change. figure 9-7 memory cycle time the external bus cycles of the c167cs can be extended for a memory or peripheral, which cannot keep pace with the controllers maximum speed, by introducing wait states during the access (see figure 9-7 ). during these memory cycle time wait states, the cpu is idle, if this access is required for the execution of the current instruction. the memory cycle time wait states can be programmed in increments of one cpu clock (2 tcl) within a range from 0 to 15 (default after reset) via the mctc fields of the buscon registers. 15 C waitstates will be inserted. mct02063 address segment ale bus (p0) address rd address data bus (p0) wr mctc wait states (1...15) bus cycle data/instr.
c167cs derivatives the external bus interface users manual 9-15 v2.0, 2000-07 programmable memory tri-state time the c167cs allows the user to adjust the time between two subsequent external accesses to account for the tri-state time of the external device. the tri-state time defines, when the external device has released the bus after deactivation of the read command (rd ). figure 9-8 memory tri-state time the output of the next address on the external bus can be delayed for a memory or peripheral, which needs more time to switch off its bus drivers, by introducing a wait state after the previous bus cycle (see figure 9-8 ). during this memory tri-state time wait state, the cpu is not idle, so cpu operations will only be slowed down if a subsequent external instruction or data fetch operation is required during the next instruction cycle. the memory tri-state time waitstate requires one cpu clock (2 tcl) and is controlled via the mttcx bits of the buscon registers. a waitstate will be inserted, if bit mttcx is 0 (default after reset). note: external bus cycles in multiplexed bus modes implicitly add one tri-state time waitstate in addition to the programmable mttc waitstate. mct02065 segment ale bus (p0) address rd mttc wait state address bus cycle data/instr.
c167cs derivatives the external bus interface users manual 9-16 v2.0, 2000-07 read/write signal delay the c167cs allows the user to adjust the timing of the read and write commands to account for timing requirements of external peripherals. the read/write delay controls the time between the falling edge of ale and the falling edge of the command. without read/write delay the falling edges of ale and command(s) are coincident (except for propagation delays). with the delay enabled, the command(s) become active half a cpu clock (1 tcl) after the falling edge of ale. the read/write delay does not extend the memory cycle time, and does not slow down the controller in general. in multiplexed bus modes, however, the data drivers of an external device may conflict with the c167css address, when the early rd signal is used. therefore multiplexed bus cycles should always be programmed with read/write delay. the read/write delay is controlled via the rwdcx bits in the buscon registers. the command(s) will be delayed, if bit rwdcx is 0 (default after reset). early wr signal deactivation the duration of an external write access can be shortened by one tcl. the wr signal is activated (driven low) in the standard way, but can be deactivated (driven high) one tcl earlier than defined in the standard timing. in this case also the data output drivers will be deactivated one tcl earlier. this is especially useful in systems which operate on higher cpu clock frequencies and employ external modules (memories, peripherals, etc.) which switch on their own data drivers very fast in response to e.g. a chip select signal. conflicts between the c167css and the external peripherals output drivers can be avoided then by selecting early wr for the c167cs. note: make sure that the reduced wr low time then still matches the requirements of the external peripheral/memory. early wr deactivation is controlled via the ewenx bits in the buscon registers. the wr signal will be shortened if bit ewenx is 1 (default after reset is a standard wr signal, i.e. ewenx = 0).
c167cs derivatives the external bus interface users manual 9-17 v2.0, 2000-07 figure 9-9 read/write signal duration control mct04005 address segment ale bus (p0) 1) rd address data bus (p0) wr read/write delay bus cycle data/instr. early write 2) 3) 4) 1) the data drivers from the previous bus cycle should be disabled when the rd signal becomes active. 2) data drivers are disabled in an early-write cycle. 3) data drivers are disabled in a demultiplexed normal-write cycle. 4) data drivers are disabled in a multiplexed normal-write cycle.
c167cs derivatives the external bus interface users manual 9-18 v2.0, 2000-07 9.4 ready controlled bus cycles for situations, where the programmable waitstates are not enough, or where the response (access) time of a peripheral is not constant, the c167cs provides external bus cycles that are terminated via a ready input signal (synchronous or asynchronous). in this case the c167cs first inserts a programmable number of waitstates (0 7) and then monitors the ready line to determine the actual end of the current bus cycle. the external device drives ready low in order to indicate that data have been latched (write cycle) or are available (read cycle). figure 9-10 ready controlled bus cycles the ready function is enabled via the rdyenx bits in the buscon registers. when this function is selected (rdyenx = 1), only the lower 3 bits of the respective mctc bit field define the number of inserted waitstates (0 7), while the msb of bit field mctc selects the ready operation: mctc.3 = 0: synchronous ready , i.e. the ready signal must meet setup and hold times. mctc.3 = 1: asynchronous ready , i.e. the ready signal is synchronized internally. evaluation (sampling) of the ready input aready sready : rd/wr ale 2. ws with active ready 1. ws bus cycle mcd02237 extended via ready 1. ws 2. ws bus cycle
c167cs derivatives the external bus interface users manual 9-19 v2.0, 2000-07 the synchronous ready provides the fastest bus cycles, but requires setup and hold times to be met. the clkout signal should be enabled and may be used by the peripheral logic to control the ready timing in this case. the asynchronous ready is less restrictive, but requires additional waitstates caused by the internal synchronization. as the asynchronous ready is sampled earlier (see figure 9-10 ) programmed waitstates may be necessary to provide proper bus cycles (see also notes on normally-ready peripherals below). a ready signal (especially asynchronous ready ) that has been activated by an external device may be deactivated in response to the trailing (rising) edge of the respective command (rd or wr ). note: when the ready function is enabled for a specific address window, each bus cycle within this window must be terminated with an active ready signal. otherwise the controller hangs until the next reset. a timeout function is only provided by the watchdog timer. combining the ready function with predefined waitstates is advantageous in two cases: memory components with a fixed access time and peripherals operating with ready may be grouped into the same address window. the (external) waitstate control logic in this case would activate ready either upon the memorys chip select or with the peripherals ready output. after the predefined number of waitstates the c167cs will check its ready line to determine the end of the bus cycle. for a memory access it will be low already (see example a) in figure 9-10 ), for a peripheral access it may be delayed (see example b) in figure 9-10 ). as memories tend to be faster than peripherals, there should be no impact on system performance. when using the ready function with so-called normally-ready peripherals, it may lead to erroneous bus cycles, if the ready line is sampled too early. these peripherals pull their ready output low, while they are idle. when they are accessed, they deactivate ready until the bus cycle is complete, then drive it low again. if, however, the peripheral deactivates ready after the first sample point of the c167cs, the controller samples an active ready and terminates the current bus cycle, which, of course, is too early. by inserting predefined waitstates the first ready sample point can be shifted to a time, where the peripheral has safely controlled the ready line (e.g. after 2 waitstates in figure 9-10 ).
c167cs derivatives the external bus interface users manual 9-20 v2.0, 2000-07 9.5 controlling the external bus controller a set of registers controls the functions of the ebc. general features like the usage of interface pins (wr , bhe ), segmentation and internal rom mapping are controlled via register syscon. the properties of a bus cycle like chip select mode, usage of ready , length of ale, external bus mode, read/write delay and waitstates are controlled via registers buscon4 buscon0. four of these registers (buscon4 buscon1) have an address select register (addrsel4 addrsel1) associated with them, which allows to specify up to four address areas and the individual bus characteristics within these areas. all accesses that are not covered by these four areas are then controlled via buscon0. this allows to use memory components or peripherals with different interfaces within the same system, while optimizing accesses to each of them. syscon system control register sfr (ff12 h /89 h ) reset value: 0xx0 h 151413121110987654321 0 stksz rom s1 sgt dis rom en byt dis clk en wr cfg cs cfg - owd dis bd rst en xpen visi- ble xper sha-re rw rw rw rwh rwh rw rwh rw - rwh rw rw rw rw bit function xper-share xbus peripheral share mode control 0: external accesses to xbus peripherals are disabled 1: xbus peripherals are accessible via the ext. bus during hold mode visible visible mode control 0: accesses to xbus peripherals are done internally 1: xbus peripheral accesses are made visible on the external pins xpen xbus peripheral enable bit 0: accesses to the on-chip x-peripherals and their functions are disabled 1: the on-chip x-peripherals are enabled and can be accessed bdrsten bidirectional reset enable bit 0: pin rstin is an input only. 1: pin rstin is pulled low during the internal reset sequence after any reset. owddis oscillator watchdog disable bit (configured via pin rd upon a reset) 0: the on-chip oscillator watchdog is enabled and active. 1: the on-chip oscillator watchdog is disabled and the cpu clock is always fed from the oscillator input.
c167cs derivatives the external bus interface users manual 9-21 v2.0, 2000-07 note: register syscon cannot be changed after execution of the einit instruction. bit sgtdis controls the correct stack operation (push/pop of csp or not) during traps and interrupts. the layout of the buscon registers and addrsel registers is identical (respectively). registers buscon4 buscon1, which control the selected address windows, are completely under software control, while register buscon0, which e.g. is also used for the very first code access after reset, is partly controlled by hardware, i.e. it is initialized via port0 during the reset sequence. this hardware control allows to define an appropriate external bus for systems, where no internal program memory is provided. cscfg chip select configuration control (cleared after reset) 0: latched cs mode. the cs signals are latched internally and driven to the (enabled) port pins synchronously. 1: unlatched cs mode. the cs signals are directly derived from the address and driven to the (enabled) port pins. wrcfg write configuration control (configured via pin p0h.0 upon a reset) 0: pins wr and bhe retain their normal function 1: pin wr acts as wrl , pin bhe acts as wrh clken system clock output enable (clkout, cleared after reset) 0: clkout disabled: pin may be used for fout or gen. purpose io 1: clkout enabled: pin outputs the system clock signal bytdis disable/enable control for pin bhe (set according to data bus width) 0: pin bhe enabled 1: pin bhe disabled, pin may be used for general purpose io romen internal rom enable (set according to pin ea during reset) 0: internal program memory disabled, accesses to the rom area use the external bus 1: internal program memory enabled sgtdis segmentation disable/enable control (cleared after reset) 0: segmentation enabled (csp is saved/restored during interrupt entry/exit) 1: segmentation disabled (only ip is saved/restored) roms1 internal rom mapping 0: internal rom area mapped to segment 0 (000000 h 007fff h ) 1: internal rom area mapped to segment 1 (010000 h 017fff h ) stksz system stack size selects the size of the system stack (in the internal ram) from 32 to 1024 words bit function
c167cs derivatives the external bus interface users manual 9-22 v2.0, 2000-07 buscon0 bus control register 0 sfr (ff0c h /86 h ) reset value: 0xx0 h 1514131211109876543210 csw en0 csr en0 - rdy en0 bsw c0 bus act 0 ale ctl 0 ew en0 btyp mtt c0 rwd c0 mctc rw rw - rw rw rwh rwh rw rwh rw rw rw buscon1 bus control register 1 sfr (ff14 h /8a h ) reset value: 0000 h 1514131211109876543210 csw en1 csr en1 - rdy en1 bsw c1 bus act 1 ale ctl 1 ew en1 btyp mtt c1 rwd c1 mctc rw rw - rw rw rw rw rw rw rw rw rw buscon2 bus control register 2 sfr (ff16 h /8b h ) reset value: 0000 h 1514131211109876543210 csw en2 csr en2 - rdy en2 bsw c2 bus act 2 ale ctl 2 ew en2 btyp mtt c2 rwd c2 mctc rw rw - rw rw rw rw rw rw rw rw rw buscon3 bus control register 3 sfr (ff18 h /8c h ) reset value: 0000 h 1514131211109876543210 csw en3 csr en3 - rdy en3 bsw c3 bus act 3 ale ctl 3 ew en3 btyp mtt c3 rwd c3 mctc rw rw - rw rw rw rw rw rw rw rw rw buscon4 bus control register 4 sfr (ff1a h /8d h ) reset value: 0000 h 1514131211109876543210 csw en4 csr en4 - rdy en4 bsw c4 bus act 4 ale ctl 4 ew en4 btyp mtt c4 rwd c4 mctc rw rw - rw rw rw rw rw rw rw rw rw
c167cs derivatives the external bus interface users manual 9-23 v2.0, 2000-07 bit function mctc memory cycle time control (number of memory cycle time wait states) 0000: 15 waitstates (number = 15 C ) 1111: no waitstates note: the definition of bitfield mctcx changes if rdyenx = 1 (see chapter 9.4 ) rwdcx read/write delay control for busconx 0: with rd/wr delay: activate command 1 tcl after falling edge of ale 1: no rd/wr delay: activate command with falling edge of ale mttcx memory tristate time control 0: 1 waitstate 1: no waitstate btyp external bus configuration 00: 8-bit demultiplexed bus 01: 8-bit multiplexed bus 10: 16-bit demultiplexed bus 11: 16-bit multiplexed bus note: for buscon0 btyp is defined via port0 during reset. ewenx early write enable 0: normal wr signal 1: early write: wr signal is deactivated and write data is tristated one tcl earlier alectlx ale lengthening control 0: normal ale signal 1: lengthened ale signal busactx bus active control 0: external bus disabled 1: external bus enabled within respective address window (addrsel) bswcx buscon switch control 0: address windows are switched immediately 1: a tristate waitstate is inserted if the next bus cycle accesses a different address window than the one controlled by this buscon register. 1) rdyenx ready input enable 0: external bus cycle is controlled by bit field mctc only 1: external bus cycle is controlled by the ready input signal
c167cs derivatives the external bus interface users manual 9-24 v2.0, 2000-07 note: buscon0 is initialized with 00c0 h , if pin ea is high during reset. if pin ea is low during reset, bits busact0 and alectl0 are set (1) and bit field btyp is loaded with the bus configuration selected via port0. csrenx read chip select enable 0: the cs signal is independent of the read command (rd ) 1: the cs signal is generated for the duration of the read command cswenx write chip select enable 0: the cs signal is independent of the write cmd. (wr ,wrl ,wrh ) 1: the cs signal is generated for the duration of the write command 1) a buscon switch waitstate is enabled by bit busconx.bswcx of the address window that is left. bit function
c167cs derivatives the external bus interface users manual 9-25 v2.0, 2000-07 addrsel1 address select register 1 sfr (ff18 h /0c h ) reset value: 0000 h 1514131211109876543210 rgsad rgsz rw rw addrsel2 address select register 2 sfr (fe1a h /0d h ) reset value: 0000 h 1514131211109876543210 rgsad rgsz rw rw addrsel3 address select register 3 sfr (fe1c h /0e h ) reset value: 0000 h 1514131211109876543210 rgsad rgsz rw rw addrsel4 address select register 4 sfr (fe1e h /0f h ) reset value: 0000 h 1514131211109876543210 rgsad rgsz rw rw bit function rgsz range size selection defines the size of the address area controlled by the respective busconx/addrselx register pair. see table 9-6 . rgsad range start address defines the upper bits of the start address of the respective address area. see table 9-6 .
c167cs derivatives the external bus interface users manual 9-26 v2.0, 2000-07 note: there is no register addrsel0, as register buscon0 controls all external accesses outside the four address windows of buscon4 buscon1 within the complete address space. definition of address areas the four register pairs buscon4/addrsel4 buscon1/addrsel1 allow to define 4 separate address areas within the address space of the c167cs. within each of these address areas external accesses can be controlled by one of the four different bus modes, independent of each other and of the bus mode specified in register buscon0. each addrselx register in a way cuts out an address window, within which the parameters in register busconx are used to control external accesses. the range start address of such a window defines the upper address bits, which are not used within the address window of the specified size (see table 9-6 ). for a given window size only those upper address bits of the start address are used (marked r), which are not implicitly used for addresses inside the window. the lower bits of the start address (marked x) are disregarded. table 9-6 address window definition bit field rgsz resulting window size relevant bits (r) of start addr. (a12 ) 0 0 0 0 0 0 0 1 0 0 1 0 0 0 1 1 0 1 0 0 0 1 0 1 0 1 1 0 0 1 1 1 1 0 0 0 1 0 0 1 1 0 1 0 1 0 1 1 1 1 x x 4 kbyte 8 kbyte 16 kbyte 32 kbyte 64 kbyte 128 kbyte 256 kbyte 512 kbyte 1 mbyte 2 mbyte 4 mbyte 8 mbyte reserved. rrrrrrrrrrrr rrrrrrrrrrrx rrrrrrrrrrx x rrrrrrrrrx x x rrrrrrrrx x x x rrrrrrrx x x x x rrrrrrx x x x x x rrrrrx x x x x x x rrrrx x x x x x x x rrrxxxxxxxxx rrxxxxxxxxxx rxxxxxxxxxxx
c167cs derivatives the external bus interface users manual 9-27 v2.0, 2000-07 address window arbitration the address windows that can be defined within the c167css address space may partly overlap each other. thus e.g. small areas may be cut out of bigger windows in order to effectively utilize external resources, especially within segment 0. for each access the ebc compares the current address with all address select registers (programmable addrselx and hardwired xadrsx). this comparison is done in four levels. priority 1 : the hardwired xadrsx registers are evaluated first. a match with one of these registers directs the access to the respective x-peripheral using the corresponding xbconx register and ignoring all other addrselx regis- ters. priority 2 : registers addrsel2 and addrsel4 are evaluated before addrsel1 and addrsel3, respectively. a match with one of these registers directs the access to the respective external area using the corresponding bus- conx register and ignoring registers addrsel1/3 (see figure 9-11 ). priority 3 : a match with registers addrsel1 or addrsel3 directs the access to the respective external area using the corresponding busconx register. priority 4 : if there is no match with any xadrsx or addrselx register the access to the external bus uses register buscon0. figure 9-11 address window arbitration note: only the indicated overlaps are defined. all other overlaps lead to erroneous bus cycles. e.g. addrsel4 may not overlap addrsel2 or addrsel1. the hardwired xadrsx registers are defined non-overlapping. mca04368 xbcon0 buscon2 buscon1 buscon0 buscon4 buscon3 active window inactive window
c167cs derivatives the external bus interface users manual 9-28 v2.0, 2000-07 note: rp0h is initialized during the reset configuration and permits to check the current configuration. this configuration (except for bit wrc) can be changed via register rstcon (see section 20.5 ). rp0h reset value of p0h sfr (f108 h /84 h ) reset value: - - xx h 1514131211109876543210 clkcfg salsel cssel wrc rh rh rh rh bit function wrc write configuration 0: pins wr and bhe operate as wrl and wrh signals 1: pins wr and bhe operate as wr and bhe signals cssel chip select line selection (number of active cs outputs) 00: 3 cs lines: cs2 cs0 01: 2 cs lines: cs1 cs0 10: no cs lines at all 11: 5 cs lines: cs4 cs0 (default without pulldowns) salsel segment address line selection (nr. of active segment addr. outputs) 00: 4-bit segment address: a19 a16 01: no segment address lines at all 10: 8-bit segment address: a23 a16 11: 2-bit segment address: a17 a16 (default without pulldowns) clkcfg clock generation mode configuration these pins define the clock generation mode, i.e. the mechanism how the internal cpu clock is generated from the externally applied (xtal) input clock.
c167cs derivatives the external bus interface users manual 9-29 v2.0, 2000-07 precautions and hints ? the ext. bus interface is enabled as long as at least one of the buscon registers has its busact bit set. ? port1 will output the intra-segment addr. as long as at least one of the buscon registers selects a demultiplexed external bus, even for multiplexed bus cycles. ? not all addr. windows defined via registers addrselx may overlap each other. the operation of the ebc will be unpredictable in such a case. see address window arbitration on page 9-27 . ? the addr. windows defined via registers addrselx may overlap internal addr. areas. internal accesses will be executed in this case. ? for any access to an internal addr. area the ebc will remain inactive (see chapter 9.6 ).
c167cs derivatives the external bus interface users manual 9-30 v2.0, 2000-07 9.6 ebc idle state when the external bus interface is enabled, but no external access is currently executed, the ebc is idle. as long as only internal resources (from an architecture point of view) like iram, gprs or sfrs, etc. are used the external bus interface does not change (see table 9-7 ). accesses to on-chip x-peripherals are also controlled by the ebc. however, even though an x-peripheral appears like an external peripheral to the controller, the respective accesses do not generate valid external bus cycles. due to timing constraints address and write data of an xbus cycle are reflected on the external bus interface (see table 9-7 ). the address mentioned above includes port1, port 4, bhe and ale which also pulses for an xbus cycle. the external cs signals on port 6 are driven inactive (high) because the ebc switches to an internal xcs signal. the external control signals (rd and wr or wrl /wrh if enabled) remain inactive (high). table 9-7 status of the external bus interface during ebc idle state pins internal accesses only xbus accesses port0 tristated (floating) tristated (floating) for read accesses xbus write data for write accesses port1 last used external address (if used for the bus interface) last used xbus address (if used for the bus interface) 1) 1) used and driven in visible mode. port 4 last used external segment address (on selected pins) last used xbus segment address (on selected pins) port 6 active external cs signal corresponding to last used address inactive (high) for selected cs signals bhe level corresponding to last external access level corresponding to last xbus access ale inactive (low) pulses as defined for x-peripheral rd inactive (high) inactive (high) 1) wr /wrl inactive (high) inactive (high) 1) wrh inactive (high) inactive (high) 1)
c167cs derivatives the external bus interface users manual 9-31 v2.0, 2000-07 9.7 external bus arbitration in embedded systems it may be efficient to share external resources like memory banks or peripheral devices among more than one microcontroller or processor. the c167cs supports this approach with the possibility to arbitrate the access to its external bus, i.e. to the external resources. several bus masters can therefore use the same set of resources, resulting in compact, though powerful systems. note: sharing external resources is useful if these resources are used to a limited amount only. the performance of a bus master which relies on these external resources to a great extent (e.g. external code) will be reduced by the bandwidth used by the other masters. bus arbitration uses three control signals (hold , hlda /bgr , breq ) and can be enabled and disabled via software (psw.hlden), e.g. in order to protect time-critical code sections from being suspended by other bus masters. a bus arbiter logic can be designed to determine which of the bus masters controls the external system at a given time. using the specific master and slave modes for bus arbitration saves external glue logic (bus arbiter) when connecting two devices of the c166 family. note: bus arbitration does not work if there is no clock signal for the ebc, i.e. during idle mode and powerdown mode. signals and control the upper three pins of port 6 are used for the bus arbitration interface. table 9-8 summarizes the functions of these interface lines. the external bus arbitration is enabled by setting bit hlden in register psw to 1. in this case the three bus arbitration pins hold , hlda and breq are automatically controlled by the ebc independent of their io configuration. bit hlden may be cleared during the execution of program sequences, where the external resources are required but cannot be shared with other bus masters, or during sequences which need to access on-chip xbus resources but which shall not be interrupted by hold states. in this case the c167cs will not answer to hold requests from other external masters. if hlden is cleared while the c167cs is in hold state (code execution from internal ram/rom) this hold state is left only after hold has been deactivated again. i.e. in this case the current hold state continues and only the next hold request is not answered. note: the pins hold , hlda and breq keep their alternate function (bus arbitration) even after the arbitration mechanism has been switched off by clearing hlden. all three pins are used for bus arbitration after bit hlden was set once.
c167cs derivatives the external bus interface users manual 9-32 v2.0, 2000-07 arbitration sequences an external master may request the c167css bus via the hold input. after completing the currently running bus cycle the c167cs acknowledges this request via the hlda output and will then float its bus lines (internal pullups at csx , rd , and wr , internal pulldown at ale). the new master may now access the peripheral devices or memory banks via the same interface lines as the c167cs. during this time the c167cs can keep on executing, as long as it does not need access to the external bus. all actions that just require internal resources like instruction or data memory and on-chip generic peripherals, may be executed in parallel. note: the xbus is an internal representation of the external bus interface. accesses to xbus peripherals use the ebc and therefore also cannot be executed during the bus hold state. when the c167cs needs access to its external bus while it is occupied by another bus master, it demands it via the breq output. the arbiter can then remove the current master from the bus. this is indicated to the c167cs by deactivating its hold input. the c167cs responds by deactivating its hlda signal, and then taking control of the external bus itself. of course also the request signal breq is deactivated after getting control of the bus back. table 9-8 interface pins for bus arbitration pin function direction operational description p6.5 hold input the hold request signal requests the external bus system from the c167cs. p6.6 hlda (master mode) output the hold acknowledge signal acknowledges a hold request and indicates to the external partners that the c167cs has withdrawn from the bus and another external bus master may now use it. bgr 1) (slave mode) input the bus grant signal indicates to the c167cs (slave) that the master has withdrawn from the external bus in response to the slaves breq . the slave may now use the external bus system until the master requests it back. p6.7 breq output the bus request signal indicates to the bus arbiter logic that the c167cs requires control over the external bus, which has been released and is currently controlled by another bus master. 1) in slave mode pin hlda inverts its direction to input. the changed functionality is indicated through the different name.
c167cs derivatives the external bus interface users manual 9-33 v2.0, 2000-07 entering the hold state access to the c167css external bus is requested by driving its hold input low. after synchronizing this signal the c167cs will complete a current external bus cycle or xbus cycle (if any is active), release the external bus and grant access to it by driving the hlda output low. during hold state the c167cs treats the external bus interface as follows: ? address and data bus(es) float to tri-state ? ale is pulled low by an internal pulldown device ? command lines are pulled high by internal pullup devices (rd , wr ) ?csx outputs are driven high for 1 tcl and then pulled high (in push/pull mode), or float to tri-state (in open drain mode) should the c167cs require access to its external bus or xbus during hold mode, it activates its bus request output breq to notify the arbitration circuitry. breq is activated only during hold mode. it will be inactive during normal operation. figure 9-12 external bus arbitration, releasing the bus note: the c167cs will complete the currently running bus cycle before granting bus access as indicated by the broken lines. this may delay hold acknowledge compared to this figure. figure 9-12 shows the first possibility for breq to get active. during bus hold pin bhe /wrh is floating. an external pullup should be used if this is required. mcd02238 hold hlda breq csx ~ ~~ ~~ ~~ ~~ ~ signals ~ ~ ~ ~ other
c167cs derivatives the external bus interface users manual 9-34 v2.0, 2000-07 exiting the hold state the external bus master returns the access rights to the c167cs by driving the hold input high. after synchronizing this signal the c167cs will drive the hlda output high, actively drive the control signals and resume executing external bus cycles if required. depending on the arbitration logic, the external bus can be returned to the c167cs under two circumstances: ? the external master does no more require access to the shared resources and gives up its own access rights, or ? the c167cs needs access to the shared resources and demands this by activating its breq output. the arbitration logic may then activate the other masters hold and so free the external bus for the c167cs, depending on the priority of the different masters. note: the hold state is not terminated by clearing bit hlden. figure 9-13 external bus arbitration, regaining the bus note: the falling breq edge shows the last chance for breq to trigger the indicated regain-sequence. even if breq is activated earlier the regain-sequence is initiated by hold going high. breq and hold are connected via an external arbitration circuitry. please note that hold may also be deactivated without the c167cs requesting the bus. mcd02236 other signals csx breq hlda hold
c167cs derivatives the external bus interface users manual 9-35 v2.0, 2000-07 connecting bus masters when multiple bus masters (c167css or other masters) shall share external resources a bus arbiter is required that determines the currently active bus master and also enables a c167cs which has surrendered its bus interface to regain control of it in case it must access the shared external resources. the structure of this bus arbiter defines the degree of control the c167cs has over the external bus system. whenever the c167cs has released the bus, there is no way of actively regaining control of it, besides the activation of the breq signal. in any case the c167cs must wait for the deactivation of its hold input. note: the full arbitration logic is required if the other bus master does not automatically remove its hold request after having used the shared resources. figure 9-14 principle arbitration logic compact two-master systems (master/slave mode) when two c167css (or other members of the c166 family) are to be connected in this way the external bus arbitration logic (normally required to combine the respective output signals hlda and breq ) can be left out. in this case one of the controllers operates in master mode (the standard default operating mode, dp6.7 = 0), while the other one must operate in slave mode (selected with dp6.7 = 1). in this configuration the master-device normally controls the external bus, while the slave-device gets control of it on demand only. in most cases this requires that (at least) the slave-device operates out of internal resources most of the time, in order to get an acceptable overall system performance. mca04369 bus arbiter logic c167cr or other master c167cr or other master c 67cr or other master hold hlda breq external bus system
c167cs derivatives the external bus interface users manual 9-36 v2.0, 2000-07 in slave mode the c167cs inverts the direction of its hlda pin and uses it as the bus grant input bgr , while the masters hlda pin remains an output. this permits the direct connection of these two signals without any additional glue logic for bus arbitration. the breq outputs are mutually connected to the other partners hold input (see figure 9-15 ). figure 9-15 sharing external resources using slave mode slave mode is selected by intentionally switching pin breq to output (dp6.7 = 1). normally the port direction register bits for the arbitration interface pins retain their reset value which is 0. clearing bit dp6.7 (or preserving the reset value) selects master mode, where the device operates compatible with earlier versions without the slave mode feature. note: if the c167cs operates in slave mode and executes a loop out of external memory which fits completely into the jump cache (e.g. jb bitaddr, $) its breq output may toggle (period = 2 cpu clock cycles). breq is activated by the prefetcher that wants to read the next sequential intstruction. breq is the deactivated, because the target of the taken jump is found in the jump cache. a loop of a minimum length of 3 words avoids this. mcs04370 c167cr in master mode c167cr in slave mode ext. bus hold hlda breq hold brg breq the pullups provide correct signal levels during the initialization phase.
c167cs derivatives the external bus interface users manual 9-37 v2.0, 2000-07 9.8 the xbus interface the c167cs provides an on-chip interface (the xbus interface), via which integrated customer/application specific peripherals can be connected to the standard controller core. the xbus is an internal representation of the external bus interface, i.e. it is operated in the same way. for each peripheral on the xbus (x-peripheral) there is a separate address window controlled by a register pair xbconx/xadrsx (similar to registers busconx and addrselx). as an interface to a peripheral in many cases is represented by just a few registers, the xadrsx registers partly select smaller address windows than the standard addrsel registers. as the xbconx/xadrsx register pairs control integrated peripherals rather than externally connected ones, they are fixed by mask programming rather than being user programmable. x-peripheral accesses provide the same choices as external accesses, so these peripherals may be bytewide or wordwide. because the on-chip connection can be realized very efficient and for performance reasons x-peripherals are only implemented with a separate address bus, i.e. in demultiplexed bus mode. interrupt nodes are provided for x-peripherals to be integrated. note: if you plan to develop a peripheral of your own to be integrated into a c167cs device to create a customer specific version, please ask for the specification of the xbus interface and for further support.
c167cs derivatives the external bus interface users manual 9-38 v2.0, 2000-07 9.8.1 accessing the on-chip xbus peripherals enabling of xbus peripherals after reset all on-chip xbus peripherals are disabled. in order to be usable an xbus peripheral must be selected via register xpercon and then enabled via the global enable bit xpen in register syscon. note: register xpercon can only be written while bit syscon.xpen = 0. while xbus peripherals are enabled (xpen = 1) xpercon is locked. table 9-9 summarizes the assignment of xpercon bits to xbus peripherals and also the number of waitstates which are used when accessing the respective peripheral. xpercon x-peripheral control register esfr (f024 h /12 h ) reset value: 0401 h 1514131211109876543210 x per 15 x per 14 x per 13 x per 12 x per 11 x per 10 x per 9 x per 8 x per 7 x per 6 x per 5 x per 4 x per 3 x per 2 x per 1 x per 0 rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw rw bit function xpern xbus module n select 0: module n is not visible, i.e. this module does not appear in the address space (address window is disabled) does not influence the port pins 1: module n is selected and can be enabled via xpen (it is then accessible and may interface to port pins) table 9-9 association of xbus peripherals to xpercon bits in the c167cs control bit associated xbus peripheral default status 1) 1) the default assignment (xpercon reset value 0401 h ) selects a set of xbus peripherals which is compatible with the c167cs. waitstates xper0 can1 selected 2 xper1 can2 off 2 xper10 xram 2 kbyte selected 0 xper11 xram 6 kbyte 2) 2) the address decoder cuts out an 8 kbyte window, even if the xram itself only provides 6 kbytes. off 0 others not assigned - -
c167cs derivatives the external bus interface users manual 9-39 v2.0, 2000-07 visible mode the c167cs can mirror on-chip access cycles to its xbus peripherals so these accesses can be observed or recorded by the external system. this function is enabled via bit visible in register syscon. accesses to xbus peripherals also use the ebc. due to timing constraints the address bus will change for all accesses using the ebc. note: as xbus peripherals use demultiplexed bus cycles, the respective address is driven on port1 in visible mode, even if the external system uses mux buses only. if visible mode is activated , accesses to on-chip xbus peripherals (including control signals rd , wr , and bhe ) are mirrored to the bus interface. accesses to internal resources (program memory, iram, gprs) do not use the ebc and cannot be mirrored to outside. if visible mode is deactivated , however, no control signals (rd , wr ) will be activated, i.e. there will be no valid external bus cycles. note: visible mode can only work if the external bus is enabled at all.
c167cs derivatives the external bus interface users manual 9-40 v2.0, 2000-07 9.8.2 external accesses to xbus peripherals the on-chip xbus peripherals of the c167cs can be accessed from outside via the external bus interface under certain circumstances. in emulation mode the xbus peripherals are controlled by the bondout-chip. during normal operation this external access is accomplished selecting the xper-share mode. xper-share mode the c167cs can share its on-chip xbus peripherals with other (external) bus masters, i.e. it can allow them to access its x-peripherals while it is in hold mode. this external access is enabled via bit xpershare in register syscon and is only possible while the host controller is in hold mode. during xper-share mode the c167css bus interface inverts its direction so the external master can drive address, control, and data signals to the respective peripheral. this can be used e.g. to install a mailbox memory in a multi-processor system. note: when xper-share mode is disabled no accesses to on-chip xbus peripherals can be executed from outside.
c167cs derivatives the general purpose timer units users manual 10-1 v2.0, 2000-07 10 the general purpose timer units the general purpose timer units gpt1 and gpt2 represent very flexible multifunctional timer structures which may be used for timing, event counting, pulse width measurement, pulse generation, frequency multiplication, and other purposes. they incorporate five 16-bit timers that are grouped into the two timer blocks gpt1 and gpt2. block gpt1 contains 3 timers/counters with a maximum resolution of 16 tcl, while block gpt2 contains 2 timers/counters with a maximum resolution of 8 tcl and a 16- bit capture/reload register (caprel). each timer in each block may operate independently in a number of different modes such as gated timer or counter mode, or may be concatenated with another timer of the same block. the auxiliary timers of gpt1 may optionally be configured as reload or capture registers for the core timer. in the gpt2 block, the additional caprel register supports capture and reload operation with extended functionality, and its core timer t6 may be concatenated with timers of the capcom units (t0, t1, t7, and t8). each block has alternate input/output functions and specific interrupts associated with it. 10.1 timer block gpt1 from a programmers point of view, the gpt1 block is composed of a set of sfrs as summarized below. those portions of port and direction registers which are used for alternate functions by the gpt1 block are shaded. figure 10-1 sfrs and port pins associated with timer block gpt1 e mca04371 odp3 dp3 p3 t2 t3 t4 t2con t2ic t4ic ports & direction control alternate functions data registers control registers interrupt control p5 port 5 data register odp3 port 3 open drain control register dp3 port 3 direction control register p3 port 3 data register t2con gpt1 timer 2 control register t3con gpt1 timer 3 control register t4con gpt1 timer 4 control register p5didis port 5 digital input disable register t2 gpt1 timer 2 register t3 gpt1 timer 3 register t4 gpt1 timer 4 register t2ic gpt1 timer 2 interrupt control register t3ic gpt1 timer 3 interrupt control register t4ic gpt1 timer 4 interrupt control register t3ic t2in/p3.7 t2eud/p5.15 t3in/p3.6 t3eud/p3.4 t4in/p3.5 t4eud/p5.14 t3out/p3.3 p5 t3con p5didis t4con
c167cs derivatives the general purpose timer units users manual 10-2 v2.0, 2000-07 all three timers of block gpt1 (t2, t3, t4) can run in 4 basic modes, which are timer, gated timer, counter and incremental interface mode, and all timers can either count up or down. each timer has an alternate input function pin (txin) associated with it which serves as the gate control in gated timer mode, or as the count input in counter mode. the count direction (up/down) may be programmed via software or may be dynamically altered by a signal at an external control input pin. each overflow/underflow of core timer t3 is latched in the toggle flipflop t3otl and may be indicated on an alternate output function pin. the auxiliary timers t2 and t4 may additionally be concatenated with the core timer, or used as capture or reload registers for the core timer. the current contents of each timer can be read or modified by the cpu by accessing the corresponding timer registers t2, t3, or t4, which are located in the non-bitaddressable sfr space. when any of the timer registers is written to by the cpu in the state immediately before a timer increment, decrement, reload, or capture is to be performed, the cpu write operation has priority in order to guarantee correct results. figure 10-2 gpt1 block diagram t3 mode control 2 n : 1 f cpu 2 n : 1 f cpu t2 mode control gpt1 timer t2 reload capture 2 n : 1 f cpu t4 mode control gpt1 timer t4 reload capture gpt1 timer t3 t3otl u/d t2eud t2in t3in t3eud t4in t4eud t3out toggle ff u/d u/d interrupt request interrupt request interrupt request other timers mct02141 n = 3 10
c167cs derivatives the general purpose timer units users manual 10-3 v2.0, 2000-07 10.1.1 gpt1 core timer t3 the core timer t3 is configured and controlled via its bitaddressable control register t3con. t3con timer 3 control register sfr (ff42 h /a1 h ) reset value: 0000 h 1514131211109876543210 ----- t3 otl t3 oe t3 ude t3 ud t3r t3m t3i - - - - - rwh rw rw rw rw rw rw bit function t3i timer 3 input selection depends on the operating mode, see respective sections. t3m timer 3 mode control (basic operating mode) 000: timer mode 001: counter mode 010: gated timer with gate active low 011: gated timer with gate active high 100: reserved . do not use this combination. 101: reserved . do not use this combination. 110: incremental interface mode 111: reserved . do not use this combination. t3r timer 3 run bit 0: timer/counter 3 stops 1: timer/counter 3 runs t3ud timer 3 up/down control 1) 1) for the effects of bits t3ud and t3ude refer to the direction table 10-1 . t3ude timer 3 external up/down enable 1) t3oe alternate output function enable 0: alternate output function disabled 1: alternate output function enabled t3otl timer 3 output toggle latch toggles on each overflow/underflow of t3. can be set or reset by software.
c167cs derivatives the general purpose timer units users manual 10-4 v2.0, 2000-07 timer 3 run bit the timer can be started or stopped by software through bit t3r (timer t3 run bit). if t3r = 0, the timer stops. setting t3r to 1 will start the timer.in gated timer mode, the timer will only run if t3r = 1 and the gate is active (high or low, as programmed). count direction control the count direction of the core timer can be controlled either by software or by the external input pin t3eud (timer t3 external up/down control input), which is the alternate input function of port pin p3.4. these options are selected by bits t3ud and t3ude in control register t3con. when the up/down control is done by software (bit t3ude = 0), the count direction can be altered by setting or clearing bit t3ud. when t3ude = 1, pin t3eud is selected to be the controlling source of the count direction. however, bit t3ud can still be used to reverse the actual count direction, as shown in table 10-1 . if t3ud = 0 and pin t3eud shows a low level, the timer is counting up. with a high level at t3eud the timer is counting down. if t3ud = 1, a high level at pin t3eud specifies counting up, and a low level specifies counting down. the count direction can be changed regardless of whether the timer is running or not. when pin t3eud/p3.4 is used as external count direction control input, it must be configured as input, i.e. its corresponding direction control bit dp3.4 must be set to 0. note: the direction control works the same for core timer t3 and for auxiliary timers t2 and t4. therefore the pins and bits are named tx table 10-1 gpt1 core timer t3 count direction control pin txeud bit txude bit txud count direction x 0 0 count up x 0 1 count down 0 1 0 count up 1 1 0 count down 0 1 1 count down 1 1 1 count up
c167cs derivatives the general purpose timer units users manual 10-5 v2.0, 2000-07 timer 3 output toggle latch an overflow or underflow of timer t3 will clock the toggle bit t3otl in control register t3con. t3otl can also be set or reset by software. bit t3oe (alternate output function enable) in register t3con enables the state of t3otl to be an alternate function of the external output pin t3out. for that purpose, a 1 must be written into the respective port data latch and pin t3out must be configured as output by setting the corresponding direction control bit to 1. if t3oe = 1, pin t3out then outputs the state of t3otl. if t3oe = 0, pin t3out can be used as general purpose io pin. in addition, t3otl can be used in conjunction with the timer over/underflows as an input for the counter function or as a trigger source for the reload function of the auxiliary timers t2 and t4. for this purpose, the state of t3otl does not have to be available at pin t3out, because an internal connection is provided for this option. timer 3 in timer mode timer mode for the core timer t3 is selected by setting bit field t3m in register t3con to 000 b . in this mode, t3 is clocked with the internal system clock (cpu clock) divided by a programmable prescaler, which is selected by bit field t3i. the input frequency f t3 for timer t3 and its resolution r t3 are scaled linearly with lower clock frequencies f cpu , as can be seen from the following formula: figure 10-3 block diagram of core timer t3 in timer mode f t3 = f cpu 8 2 r t3 [ m s] = f cpu [mhz] 8 2 , core timer tx txotl interrupt request txoe txout txr 2 n : 1 txl exor 0 mux 1 txeud txude mcb02028 txud f cpu up/ down t3eud = p3.4 x = 3 t3out = p3.3 n = 3 10
c167cs derivatives the general purpose timer units users manual 10-6 v2.0, 2000-07 the timer input frequencies, resolution and periods which result from the selected prescaler option are listed in table 10-2 . this table also applies to the gated timer mode of t3 and to the auxiliary timers t2 and t4 in timer and gated timer mode. note that some numbers may be rounded to 3 significant digits. table 10-2 gpt1 timer input frequencies, resolution and periods @ 20 mhz f cpu = 20 mhz timer input selection t2i/t3i/t4i 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler factor 8 16 32 64 128 256 512 1024 input frequency 2.5 mhz 1.25 mhz 625 khz 312.5 khz 156.25 khz 78.125 khz 39.06 khz 19.53 khz resolution 400 ns 800 ns 1.6 m s3.2 m s6.4 m s 12.8 m s 25.6 m s 51.2 m s period 26.2 ms 52.5 ms 105 ms 210 ms 420 ms 840 ms 1.68 s 3.36 s table 10-3 gpt1 timer input frequencies, resolution and periods @ 25 mhz f cpu = 25 mhz timer input selection t2i/t3i/t4i 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler factor 8 16 32 64 128 256 512 1024 input frequency 3.125 mhz 1.56 mhz 781.25 khz 390.62 khz 195.3 khz 97.65 khz 48.83 khz 24.42 khz resolution 320 ns 640 ns 1.28 m s2.56 m s5.12 m s 10.2 m s 20.5 m s 41.0 m s period 21.0 ms 41.9 ms 83.9 ms 168 ms 336 ms 671 ms 1.34 s 2.68 s table 10-4 gpt1 timer input frequencies, resolution and periods @ 33 mhz f cpu = 33 mhz timer input selection t2i/t3i/t4i 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler factor 8 16 32 64 128 256 512 1024 input frequency 4.125 mhz 2.0625 mhz 1.031 mhz 515.62 khz 257.81 khz 128.91 khz 64.45 khz 32.23 khz resolution 242 ns 485 ns 970 ns 1.94 m s3.88 m s7.76 m s 15.5 m s 31.0 m s period 15.9 ms 31.8 ms 63.6 ms 127 ms 254 ms 508 ms 1.02 s 2.03 s
c167cs derivatives the general purpose timer units users manual 10-7 v2.0, 2000-07 timer 3 in gated timer mode gated timer mode for the core timer t3 is selected by setting bit field t3m in register t3con to 010 b or 011 b . bit t3m.0 (t3con.3) selects the active level of the gate input. in gated timer mode the same options for the input frequency as for the timer mode are available. however, the input clock to the timer in this mode is gated by the external input pin t3in (timer t3 external input). to enable this operation pin t3in must be configured as input, i.e. the corresponding direction control bit must contain 0. figure 10-4 block diagram of core timer t3 in gated timer mode if t3m.0 = 0, the timer is enabled when t3in shows a low level. a high level at this pin stops the timer. if t3m.0 = 1, pin t3in must have a high level in order to enable the timer. in addition, the timer can be turned on or off by software using bit t3r. the timer will only run, if t3r = 1 and the gate is active. it will stop, if either t3r = 0 or the gate is inactive. note: a transition of the gate signal at pin t3in does not cause an interrupt request. mux core timer tx txotl interrupt request txoe txout txr xor 0 mux 1 up/ down txeud txude mcb02029 txud 2 n : 1 txi f cpu txm txin t3in = p3.6 t3eud = p3.4 x = 3 t3out = p3.3 n = 3 10
c167cs derivatives the general purpose timer units users manual 10-8 v2.0, 2000-07 timer 3 in counter mode counter mode for the core timer t3 is selected by setting bit field t3m in register t3con to 001 b . in counter mode timer t3 is clocked by a transition at the external input pin t3in. the event causing an increment or decrement of the timer can be a positive, a negative, or both a positive and a negative transition at this pin. bit field t3i in control register t3con selects the triggering transition (see table 10-5 ). figure 10-5 block diagram of core timer t3 in counter mode for counter operation, pin t3in must be configured as input, i.e. the respective direction control bit dpx.y must be 0. the maximum input frequency which is allowed in counter mode is f cpu /16. to ensure that a transition of the count input signal which is applied to t3in is correctly recognized, its level should be held high or low for at least 8 f cpu cycles before it changes. table 10-5 gpt1 core timer t3 (counter mode) input edge selection t3i triggering edge for counter increment/decrement 0 0 0 none. counter t3 is disabled 0 0 1 positive transition (rising edge) on t3in 0 1 0 negative transition (falling edge) on t3in 0 1 1 any transition (rising or falling edge) on t3in 1 x x reserved. do not use this combination core timer tx txr xor 0 mux 1 up/ down txeud txude mcb02030 txud txl txin edge select txotl txoe txout interrupt request t3in = p3.6 t3eud = p3.4 t3out = p3.3 x = 3
c167cs derivatives the general purpose timer units users manual 10-9 v2.0, 2000-07 timer 3 in incremental interface mode incremental interface mode for the core timer t3 is selected by setting bit field t3m in register t3con to 110 b . in incremental interface mode the two inputs associated with timer t3 (t3in, t3eud) are used to interface to an incremental encoder. t3 is clocked by each transition on one or both of the external input pins which gives 2-fold or 4-fold resolution of the encoder input. figure 10-6 block diagram of core timer t3 in incremental interface mode bitfield t3i in control register t3con selects the triggering transitions (see table 10-6 ). in this mode the sequence of the transitions of the two input signals is evaluated and generates count pulses as well as the direction signal. so t3 is modified automatically according to the speed and the direction of the incremental encoder and its contents therefore always represent the encoders current position. table 10-6 gpt1 core timer t3 (incremental interface mode) input edge selection t3i triggering edge for counter increment/decrement 0 0 0 none. counter t3 stops 0 0 1 any transition (rising or falling edge) on t3in 0 1 0 any transition (rising or falling edge) on t3eud 0 1 1 any transition (rising or falling edge) on any t3 input (t3in or t3eud) 1 x x reserved. do not use this combination edge select timer t3 xor 0 mux 1 t3eud t3ude mcb04000b t3u d t3l t3in t3otl interrupt request t3out phase detect t3oe t3r up/ down
c167cs derivatives the general purpose timer units users manual 10-10 v2.0, 2000-07 the incremental encoder can be connected directly to the c167cs without external interface logic. in a standard system, however, comparators will be employed to convert the encoders differential outputs (e.g. a, a ) to digital signals (e.g. a). this greatly increases noise immunity. note: the third encoder output top0, which indicates the mechanical zero position, may be connected to an external interrupt input and trigger a reset of timer t3 (e.g. via pec transfer from zeros). figure 10-7 connection of the encoder to the c167cs for incremental interface operation the following conditions must be met: ? bitfield t3m must be 110 b . ? both pins t3in and t3eud must be configured as input, i.e. the respective direction control bits must be 0. ? bit t3ude must be 1 to enable automatic direction control. the maximum counting frequency which is allowed in incremental interface mode is f cpu /16. to ensure that a transition of any input signal is correctly recognized, its level should be held high or low for at least 8 f cpu cycles before it changes. as in incremental interface mode two input signals with a 90 phase shift are evaluated, their maximum input frequency can be f cpu /32. in incremental interface mode the count direction is automatically derived from the sequence in which the input signals change, which corresponds to the rotation direction of the connected sensor. table 10-7 summarizes the possible combinations. table 10-7 gpt1 core timer t3 (incremental interface mode) count direction level on respective other input t3in input t3eud input rising falling rising falling high down up up down low up down down up mcs04372 encoder c167cr a b t0 t3input t3input interrupt a b b t0 t0 a signal conditioning
c167cs derivatives the general purpose timer units users manual 10-11 v2.0, 2000-07 figure 10-8 and figure 10-9 give examples of t3s operation, visualizing count signal generation and direction control. it also shows how input jitter is compensated which might occur if the sensor rests near to one of its switching points. figure 10-8 evaluation of the incremental encoder signals figure 10-9 evaluation of the incremental encoder signals note: timer t3 operating in incremental interface mode automatically provides information on the sensors current position. dynamic information (speed, acceleration, deceleration) may be obtained by measuring the incoming signal periods. this is facilitated by an additional special capture mode for timer t5. mct04373 forward jitter backward jitter forward t3in t3eud contents of t3 up down up note: this example shows the timer behaviour assuming that t3 counts upon any transition on input, i.e. t3i = '011 b '. mct04374 forward jitter backward jitter forward t3in up down up t3eud contents of t3 note: this example shows the timer behaviour assuming that t3 counts upon any transition on input t3in, i.e. t3i = '001 b '.
c167cs derivatives the general purpose timer units users manual 10-12 v2.0, 2000-07 10.1.2 gpt1 auxiliary timers t2 and t4 both auxiliary timers t2 and t4 have exactly the same functionality. they can be configured for timer, gated timer, counter, or incremental interface mode with the same options for the timer frequencies and the count signal as the core timer t3. in addition to these 4 counting modes, the auxiliary timers can be concatenated with the core timer, or they may be used as reload or capture registers in conjunction with the core timer. the individual configuration for timers t2 and t4 is determined by their bitaddressable control registers t2con and t4con, which are both organized identically. note that functions which are present in all 3 timers of block gpt1 are controlled in the same bit positions and in the same manner in each of the specific control registers. note: the auxiliary timers have no output toggle latch and no alternate output function. t2con timer 2 control register sfr (ff40 h /a0 h ) reset value: 0000 h 1514131211109876543210 ------- t2 ude t2 ud t2r t2m t2i - - - - - - - rw rw rw rw rw t4con timer 4 control register sfr (ff44 h /a2 h ) reset value: 0000 h 1514131211109876543210 ------- t4 ude t4 ud t4r t4m t4i - - - - - - - rw rw rw rw rw
c167cs derivatives the general purpose timer units users manual 10-13 v2.0, 2000-07 count direction control for auxiliary timers the count direction of the auxiliary timers can be controlled in the same way as for the core timer t3. the description and the table apply accordingly. timers t2 and t4 in timer mode or gated timer mode when the auxiliary timers t2 and t4 are programmed to timer mode or gated timer mode, their operation is the same as described for the core timer t3. the descriptions, figures and tables apply accordingly with one exception: ? there is no output toggle latch for t2 and t4. timers t2 and t4 in incremental interface mode when the auxiliary timers t2 and t4 are programmed to incremental interface mode, their operation is the same as described for the core timer t3. the descriptions, figures and tables apply accordingly. bit function txi timer x input selection depends on the operating mode, see respective sections. txm timer x mode control (basic operating mode) 000: timer mode 001: counter mode 010: gated timer with gate active low 011: gated timer with gate active high 100: reload mode 101: capture mode 110: incremental interface mode 111: reserved . do not use this combination. txr timer x run bit 0: timer/counter x stops 1: timer/counter x runs txud timer x up/down control 1) txude timer x external up/down enable 1) 1) for the effects of bits txud and txude refer to table 10-1 (see t3 section).
c167cs derivatives the general purpose timer units users manual 10-14 v2.0, 2000-07 timers t2 and t4 in counter mode counter mode for the auxiliary timers t2 and t4 is selected by setting bit field txm in the respective register txcon to 001 b . in counter mode timers t2 and t4 can be clocked either by a transition at the respective external input pin txin, or by a transition of timer t3s output toggle latch t3otl. figure 10-10 block diagram of an auxiliary timer in counter mode the event causing an increment or decrement of a timer can be a positive, a negative, or both a positive and a negative transition at either the respective input pin, or at the toggle latch t3otl. bit field txi in the respective control register txcon selects the triggering transition (see table 10-8 ). auxiliary timer tx interrupt request txr xor 0 mux 1 txeud txude mcb02221 txud txl txin edge select up/ down x = 2.4
c167cs derivatives the general purpose timer units users manual 10-15 v2.0, 2000-07 note: only state transitions of t3otl which are caused by the overflows/underflows of t3 will trigger the counter function of t2/t4. modifications of t3otl via software will not trigger the counter function of t2/t4. for counter operation, pin txin must be configured as input, i.e. the respective direction control bit must be 0. the maximum input frequency which is allowed in counter mode is f cpu /16. to ensure that a transition of the count input signal which is applied to txin is correctly recognized, its level should be held for at least 8 f cpu cycles before it changes. table 10-8 gpt1 auxiliary timer (counter mode) input edge selection t2i/t4i triggering edge for counter increment/decrement x 0 0 none. counter tx is disabled 0 0 1 positive transition (rising edge) on txin 0 1 0 negative transition (falling edge) on txin 0 1 1 any transition (rising or falling edge) on txin 1 0 1 positive transition (rising edge) of output toggle latch t3otl 1 1 0 negative transition (falling edge) of output toggle latch t3otl 1 1 1 any transition (rising or falling edge) of output toggle latch t3otl
c167cs derivatives the general purpose timer units users manual 10-16 v2.0, 2000-07 timer concatenation using the toggle bit t3otl as a clock source for an auxiliary timer in counter mode concatenates the core timer t3 with the respective auxiliary timer. depending on which transition of t3otl is selected to clock the auxiliary timer, this concatenation forms a 32-bit or a 33-bit timer/counter. ? 32-bit timer/counter : if both a positive and a negative transition of t3otl is used to clock the auxiliary timer, this timer is clocked on every overflow/underflow of the core timer t3. thus, the two timers form a 32-bit timer. ? 33-bit timer/counter : if either a positive or a negative transition of t3otl is selected to clock the auxiliary timer, this timer is clocked on every second overflow/underflow of the core timer t3. this configuration forms a 33-bit timer (16-bit core timer + t3otl + 16-bit auxiliary timer). the count directions of the two concatenated timers are not required to be the same. this offers a wide variety of different configurations. t3 can operate in timer, gated timer or counter mode in this case. figure 10-11 concatenation of core timer t3 and an auxiliary timer core timer ty tyotl interrupt request tyoe tyout tyr 2 n : 1 tyl mcb02034 f cpu up/down auxiliary timer tx txr txl edge select txir interrupt request *) *) note: line only affected by over/underflows of t3, but not by software modifications of t3otl. t3out = p3.3 x = 2.4, y = 3 n = 3 10
c167cs derivatives the general purpose timer units users manual 10-17 v2.0, 2000-07 auxiliary timer in reload mode reload mode for the auxiliary timers t2 and t4 is selected by setting bit field txm in the respective register txcon to 100 b . in reload mode the core timer t3 is reloaded with the contents of an auxiliary timer register, triggered by one of two different signals. the trigger signal is selected the same way as the clock source for counter mode (see table 10-8 ), i.e. a transition of the auxiliary timers input or the output toggle latch t3otl may trigger the reload. note: when programmed for reload mode, the respective auxiliary timer (t2 or t4) stops independent of its run flag t2r or t4r. figure 10-12 gpt1 auxiliary timer in reload mode upon a trigger signal t3 is loaded with the contents of the respective timer register (t2 or t4) and the interrupt request flag (t2ir or t4ir) is set. note: when a t3otl transition is selected for the trigger signal, also the interrupt request flag t3ir will be set upon a trigger, indicating t3s overflow or underflow. modifications of t3otl via software will not trigger the counter function of t2/t4. reload register tx core timer t3 up/down source/edge select t3otl interrupt request t3oe t3out txin input clock txi interrupt request mcb02035 *) note: line only affected by over/underflows of t3, but not by software modifications of t3otl. x = 2.4 *)
c167cs derivatives the general purpose timer units users manual 10-18 v2.0, 2000-07 the reload mode triggered by t3otl can be used in a number of different configurations. depending on the selected active transition the following functions can be performed: ? if both a positive and a negative transition of t3otl is selected to trigger a reload, the core timer will be reloaded with the contents of the auxiliary timer each time it overflows or underflows. this is the standard reload mode (reload on overflow/ underflow). ? if either a positive or a negative transition of t3otl is selected to trigger a reload, the core timer will be reloaded with the contents of the auxiliary timer on every second overflow or underflow. ? using this single-transition mode for both auxiliary timers allows to perform very flexible pulse width modulation (pwm). one of the auxiliary timers is programmed to reload the core timer on a positive transition of t3otl, the other is programmed for a reload on a negative transition of t3otl. with this combination the core timer is alternately reloaded from the two auxiliary timers. figure 10-13 shows an example for the generation of a pwm signal using the alternate reload mechanism. t2 defines the high time of the pwm signal (reloaded on positive transitions) and t4 defines the low time of the pwm signal (reloaded on negative transitions). the pwm signal can be output on t3out with t3oe = 1, port latch = 1 and direction bit = 1. with this method the high and low time of the pwm signal can be varied in a wide range. note: the output toggle latch t3otl is accessible via software and may be changed, if required, to modify the pwm signal. however, this will not trigger the reloading of t3.
c167cs derivatives the general purpose timer units users manual 10-19 v2.0, 2000-07 figure 10-13 gpt1 timer reload configuration for pwm generation note: although it is possible, it should be avoided to select the same reload trigger event for both auxiliary timers. in this case both reload registers would try to load the core timer at the same time. if this combination is selected, t2 is disregarded and the contents of t4 is reloaded. core timer t3 up/down t3otl interrupt request t3oe t3out interrupt request reload register t2 interrupt request reload register t4 t2i t4i input clock mcb02037 *) note: line only affected by over/underflows of t3, but not by software modifications of t3otl. *) *)
c167cs derivatives the general purpose timer units users manual 10-20 v2.0, 2000-07 auxiliary timer in capture mode capture mode for the auxiliary timers t2 and t4 is selected by setting bit field txm in the respective register txcon to 101 b . in capture mode the contents of the core timer are latched into an auxiliary timer register in response to a signal transition at the respective auxiliary timers external input pin txin. the capture trigger signal can be a positive, a negative, or both a positive and a negative transition. the two least significant bits of bit field txi are used to select the active transition (see table 10-8 ), while the most significant bit txi.2 is irrelevant for capture mode. it is recommended to keep this bit cleared (txi.2 = 0). note: when programmed for capture mode, the respective auxiliary timer (t2 or t4) stops independent of its run flag t2r or t4r. figure 10-14 gpt1 auxiliary timer in capture mode upon a trigger (selected transition) at the corresponding input pin txin the contents of the core timer are loaded into the auxiliary timer register and the associated interrupt request flag txir will be set. note: the direction control bits for t2in and t4in must be set to 0, and the level of the capture trigger signal should be held high or low for at least 8 f cpu cycles before it changes to ensure correct edge detection. capture register tx core timer t3 up/down edge select t3otl interrupt request t3oe t3out txin input clock interrupt request mcb02038 txi x = 2.4
c167cs derivatives the general purpose timer units users manual 10-21 v2.0, 2000-07 10.1.3 interrupt control for gpt1 timers when a timer overflows from ffff h to 0000 h (when counting up), or when it underflows from 0000 h to ffff h (when counting down), its interrupt request flag (t2ir, t3ir or t4ir) in register txic will be set. this will cause an interrupt to the respective timer interrupt vector (t2int, t3int or t4int) or trigger a pec service, if the respective interrupt enable bit (t2ie, t3ie or t4ie in register txic) is set. there is an interrupt control register for each of the three timers. note: please refer to the general interrupt control register description for an explanation of the control fields. t2ic timer 2 intr. ctrl. reg. sfr (ff60 h /b0 h ) reset value: - - 00 h 1514131211109876543210 - t2ir t2ie ilvl glvl - - - - - - - - rwh rw rw rw t3ic timer 3 intr. ctrl. reg. sfr (ff62 h /b1 h ) reset value: - - 00 h 1514131211109876543210 - t3ir t3ie ilvl glvl - - - - - - - - rwh rw rw rw t4ic timer 4 intr. ctrl. reg. sfr (ff64 h /b2 h ) reset value: - - 00 h 1514131211109876543210 - t4ir t4ie ilvl glvl - - - - - - - - rwh rw rw rw
c167cs derivatives the general purpose timer units users manual 10-22 v2.0, 2000-07 10.2 timer block gpt2 from a programmer s point of view, the gpt2 block is represented by a set of sfrs as summarized below. those portions of port and direction registers which are used for alternate functions by the gpt2 block are shaded. figure 10-15 sfrs and port pins associated with timer block gpt2 timer block gpt2 supports high precision event control with a maximum resolution of 8 tcl. it includes the two timers t5 and t6, and the 16-bit capture/reload register caprel. timer t6 is referred to as the core timer, and t5 is referred to as the auxiliary timer of gpt2. each timer has an alternate input function pin associated with it which serves as the gate control in gated timer mode, or as the count input in counter mode. the count direction (up/down) may be programmed via software. an overflow/underflow of t6 is indicated by the output toggle bit t6otl whose state may be output on an alternate function port pin (t6out). in addition, t6 may be reloaded with the contents of caprel. the toggle bit also supports the concatenation of t6 with auxiliary timer t5, while concatenation of t6 with the timers of the capcom units is provided through a direct connection. triggered by an external signal, the contents of t5 can be captured into register caprel, and t5 may optionally be cleared. both timer t6 and t5 can count up or down, and the current timer value can be read or modified by the cpu in the non- bitaddressable sfrs t5 and t6. e mca04375 odp3 dp3 p3 t5 t6 caprel t5con t5ic cric ports & direction control alternate functions data registers control registers interrupt control odp3 port 3 open drain control register dp3 port 3 direction control register p3 port 3 data register p5 port 5 data register p5didis port 5 digital input disable register t5congpt2 timer 5 control register t6congpt2 timer 6 control register t5 gpt2 timer 5 register t6 gpt2 timer 6 register caprelgpt2 capture/reload register t5icgpt2 timer 5 interrupt control register t6icgpt2 timer 6 interrupt control register cricgpt2 caprel interrupt control register t6ic t5in/p5.13 t5eud/p5.11 t6in/p5.12 t6eud/p5.10 capin/p3.2 t6out/p3.1 p5 t6con p5didis
c167cs derivatives the general purpose timer units users manual 10-23 v2.0, 2000-07 figure 10-16 gpt2 block diagram mux 2 n : 1 f cpu t5 mode control 2 n : 1 f cpu t6 mode control t6otl t5eud t5in t3 capin t6in t6eud t6out u/d u/d interrupt request interrupt request interrupt request other timers clear capture ct3 mcb03999 gpt2 timer t5 gpt2 caprel gpt2 timer t6 n = 2 9
c167cs derivatives the general purpose timer units users manual 10-24 v2.0, 2000-07 10.2.1 gpt2 core timer t6 the operation of the core timer t6 is controlled by its bitaddressable control register t6con. t6con timer 6 control register sfr (ff48 h /a4 h ) reset value: 0000 h 1514131211109876543210 t6 sr ---- t6 otl t6 oe t6 ude t6 ud t6r t6m t6i rw - - - - rwh rw rw rw rw rw rw bit function t6i timer 6 input selection depends on the operating mode, see respective sections. t6m timer 6 mode control (basic operating mode) 000: timer mode 001: counter mode 010: gated timer with gate active low 011: gated timer with gate active high 1xx: reserved. do not use this combination. t6r timer 6 run bit 0: timer/counter 6 stops 1: timer/counter 6 runs t6ud timer 6 up/down contro l 1) 1) for the effects of bits t6ud and t6ude refer to the table 10-9 . t6ude timer 6 external up/down enable 1) t6oe alternate output function enable 0: alternate output function disabled 1: alternate output function enabled t6otl timer 6 output toggle latch toggles on each overflow/underflow of t6. can be set or reset by software. t6sr timer 6 reload mode enable 0: reload from register caprel disabled 1: reload from register caprel enabled
c167cs derivatives the general purpose timer units users manual 10-25 v2.0, 2000-07 timer 6 run bit the timer can be started or stopped by software through bit t6r (timer t6 run bit). if t6r = 0, the timer stops. setting t6r to 1 will start the timer. in gated timer mode, the timer will only run if t6r = 1 and the gate is active (high or low, as programmed). count direction control the count direction of the core timer can be controlled either by software or by the external input pin t6eud (timer t6 external up/down control input), which is the alternate input function of port pin p5.10. these options are selected by bits t6ud and t6ude in control register t6con. when the up/down control is done by software (bit t6ude = 0), the count direction can be altered by setting or clearing bit t6ud. when t6ude = 1, pin t6eud is selected to be the controlling source of the count direction. however, bit t6ud can still be used to reverse the actual count direction, as shown in table 10-9 . if t6ud = 0 and pin t6eud shows a low level, the timer is counting up. with a high level at t6eud the timer is counting down. if t6ud = 1, a high level at pin t6eud specifies counting up, and a low level specifies counting down. the count direction can be changed regardless of whether the timer is running or not. note: the direction control works the same for core timer t6 and for auxiliary timer t5. therefore the pins and bits are named tx table 10-9 gpt2 core timer t6 count direction control pin txeud bit txude bit txud count direction x 0 0 count up x 0 1 count down 0 1 0 count up 1 1 0 count down 0 1 1 count down 1 1 1 count up
c167cs derivatives the general purpose timer units users manual 10-26 v2.0, 2000-07 timer 6 output toggle latch an overflow or underflow of timer t6 will clock the toggle bit t6otl in control register t6con. t6otl can also be set or reset by software. bit t6oe (alternate output function enable) in register t6con enables the state of t6otl to be an alternate function of the external output pin t6out. for that purpose, a 1 must be written into the respective port data latch and pin t6out must be configured as output by setting the respective direction control bit to 1. if t6oe = 1, pin t6out then outputs the state of t6otl. if t6oe = 0 pin t6out can be used as general purpose io pin. in addition, t6otl can be used in conjunction with the timer over/underflows as an input for the counter function of the auxiliary timer t5. for this purpose, the state of t6otl does not have to be available at pin t6out, because an internal connection is provided for this option. an overflow or underflow of timer t6 can also be used to clock the timers in the capcom units. for this purpose, there is a direct internal connection between timer t6 and the capcom timers. timer 6 in timer mode timer mode for the core timer t6 is selected by setting bitfield t6m in register t6con to 000 b . in this mode, t6 is clocked with the internal system clock divided by a programmable prescaler, which is selected by bit field t6i. the input frequency f t6 for timer t6 and its resolution r t6 are scaled linearly with lower clock frequencies f cpu , as can be seen from the following formula: figure 10-17 block diagram of core timer t6 in timer mode f t6 = f cpu 4 2 r t6 [ m s] = f cpu [mhz] 4 2 , core timer tx txotl interrupt request txoe txout txr 2 n : 1 txl exor 0 mux 1 txeud txude mcb02028 txud f cpu up/ down t6eud = p5.10 x = 6 t6out = p3.1 n = 2 9
c167cs derivatives the general purpose timer units users manual 10-27 v2.0, 2000-07 the timer input frequencies, resolution and periods which result from the selected prescaler option are listed in table 10-10 . this table also applies to the gated timer mode of t6 and to the auxiliary timer t5 in timer and gated timer mode. note that some numbers may be rounded to 3 significant digits. table 10-10 gpt2 timer input frequencies, resolution and periods @ 20 mhz f cpu = 20 mhz timer input selection t5i/t6i 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler factor 4 8 16 32 64 128 256 512 input frequency 5 mhz 2.5 mhz 1.25 mhz 625 khz 312.5 khz 156.25 khz 78.125 khz 39.06 khz resolution 200 ns 400 ns 800 ns 1.6 m s3.2 m s6.4 m s 12.8 ms 25.6 m s period 13 ms 26 ms 52.5 ms 105 ms 210 ms 420 ms 840 ms 1.68 s table 10-11 gpt2 timer input frequencies, resolution and periods @ 25 mhz f cpu = 25 mhz timer input selection t5i/t6i 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler factor 4 8 16 32 64 128 256 512 input frequency 6.25 mhz 3.125 mhz 1.56 mhz 781.25 khz 390.62 khz 195.31 khz 97.66 khz 48.83 khz resolution 160 ns 320 ns 640 ns 1.28 m s2.56 m s5.12 m s 10.2 ms 20.5 m s period 10.5 ms 21 ms 42 ms 83.9 ms 168 ms 336 ms 671 ms 1.34 s table 10-12 gpt2 timer input frequencies, resolution and periods @ 33 mhz f cpu = 33 mhz timer input selection t5i/t6i 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler factor 4 8 16 32 64 128 256 512 input frequency 2.06 mhz 4.125 mhz 2.0625 mhz 1.031 mhz 515.62 khz 257.81 khz 128.91 khz 64.45 khz resolution 121 ns 242 ns 485 ns 970 ns 1.94 m s3.88 m s7.76 m s 15.5 m s period 7.9 ms 15.9 ms 31.8 ms 63.6 ms 127 ms 254 ms 508 ms 1.02 s
c167cs derivatives the general purpose timer units users manual 10-28 v2.0, 2000-07 timer 6 in gated timer mode gated timer mode for the core timer t6 is selected by setting bit field t6m in register t6con to 010 b or 011 b . bit t6m.0 (t6con.3) selects the active level of the gate input. in gated timer mode the same options for the input frequency as for the timer mode are available. however, the input clock to the timer in this mode is gated by the external input pin t6in (timer t6 external input). figure 10-18 block diagram of core timer t6 in gated timer mode if t6m.0 = 0, the timer is enabled when t6in shows a low level. a high level at this pin stops the timer. if t6m.0 = 1, pin t6in must have a high level in order to enable the timer. in addition, the timer can be turned on or off by software using bit t6r. the timer will only run, if t6r = 1 and the gate is active. it will stop, if either t6r = 0 or the gate is inactive. note: a transition of the gate signal at pin t6in does not cause an interrupt request. mux core timer tx txotl interrupt request txoe txout txr xor 0 mux 1 up/ down txeud txude mcb02029 txud 2 n : 1 txi f cpu txm txin t6in = p5.12 t6eud = p5.10 x = 6 t6out = p3.1 n = 2 9
c167cs derivatives the general purpose timer units users manual 10-29 v2.0, 2000-07 timer 6 in counter mode counter mode for the core timer t6 is selected by setting bit field t6m in register t6con to 001 b . in counter mode timer t6 is clocked by a transition at the external input pin t6in, which is an alternate function of p5.12. the event causing an increment or decrement of the timer can be a positive, a negative, or both a positive and a negative transition at this pin. bit field t6i in control register t6con selects the triggering transition (see table 10-13 ). figure 10-19 block diagram of core timer t6 in counter mode the maximum input frequency which is allowed in counter mode is f cpu / 8. to ensure that a transition of the count input signal which is applied to t6in is correctly recognized, its level should be held high or low for at least 4 f cpu cycles before it changes. table 10-13 gpt2 core timer t6 (counter mode) input edge selection t6i triggering edge for counter increment/decrement 0 0 0 none. counter t6 is disabled 0 0 1 positive transition (rising edge) on t6in 0 1 0 negative transition (falling edge) on t6in 0 1 1 any transition (rising or falling edge) on t6in 1 x x reserved. do not use this combination core timer tx txr xor 0 mux 1 up/ down txeud txude mcb02030 txud txl txin edge select txotl txoe txout interrupt request t6in = p5.12 t6eud = p5.10 t6out = p3.1 x = 6
c167cs derivatives the general purpose timer units users manual 10-30 v2.0, 2000-07 10.2.2 gpt2 auxiliary timer t5 the auxiliary timer t5 can be configured for timer, gated timer or counter mode with the same options for the timer frequencies and the count signal as the core timer t6. in addition the auxiliary timer can be concatenated with the core timer (operation in counter mode). its contents may be captured to register caprel upon a selectable trigger. the individual configuration for timer t5 is determined by its bitaddressable control register t5con. note that functions which are present in both timers of block gpt2 are controlled in the same bit positions and in the same manner in each of the specific control registers. note: the auxiliary timer has no output toggle latch and no alternate output function. t5con timer 5 control register sfr (ff46 h /a3 h ) reset value: 0000 h 1514131211109876543210 t5 sc t5 clr ci - ct3 - t5 ude t5 ud t5r t5m t5i rw rw rw - rw - rw rw rw rw rw bit function t5i timer 5 input selection depends on the operating mode, see respective sections. t5m timer 5 mode control (basic operating mode) 000: timer mode 001: counter mode 010: gated timer with gate active low 011: gated timer with gate active high 1xx: reserved. do not use this combination. t5r timer 5 run bit 0: timer / counter 5 stops 1: timer / counter 5 runs t5ud timer 5 up / down control 1) t5ude timer 5 external up/down enable 1) ct3 timer 3 capture trigger enable 0: capture trigger from pin capin 1: capture trigger from t3 input pins
c167cs derivatives the general purpose timer units users manual 10-31 v2.0, 2000-07 count direction control for auxiliary timer the count direction of the auxiliary timer can be controlled in the same way as for the core timer t6. the description and the table apply accordingly. timer t5 in timer mode or gated timer mode when the auxiliary timer t5 is programmed to timer mode or gated timer mode, its operation is the same as described for the core timer t6. the descriptions, figures and tables apply accordingly with one exception: ? there is no output toggle latch for t5. timer t5 in counter mode counter mode for the auxiliary timer t5 is selected by setting bit field t5m in register t5con to 001 b . in counter mode timer t5 can be clocked either by a transition at the external input pin t5in, or by a transition of timer t6s output toggle latch t6otl (i.e. timer concatenation). ci register caprel capture trigger selection (depending on bit ct3) 00: capture disabled 01: positive transition (rising edge) on capin or any transition on t3in 10: negative transition (falling edge) on capin or any transition on t3eud 11: any transition (rising or falling edge) on capin or any transition on t3in or t3eud t5clr timer 5 clear bit 0: timer 5 not cleared on a capture 1: timer 5 is cleared on a capture t5sc timer 5 capture mode enable 0: capture into register caprel disabled 1: capture into register caprel enabled 1) for the effects of bits t5ud and t5ude refer to the direction table (see t6 section). bit function
c167cs derivatives the general purpose timer units users manual 10-32 v2.0, 2000-07 figure 10-20 block diagram of auxiliary timer t5 in counter mode the event causing an increment or decrement of the timer can be a positive, a negative, or both a positive and a negative transition at either the input pin, or at the toggle latch t6otl. bitfield t5i in control register t5con selects the triggering transition (see table 10-14 ). note: only state transitions of t6otl which are caused by the overflows/underflows of t6 will trigger the counter function of t5. modifications of t6otl via software will not trigger the counter function of t5. the maximum input frequency which is allowed in counter mode is f cpu / 8. to ensure that a transition of the count input signal which is applied to t5in is correctly recognized, its level should be held high or low for at least 4 f cpu cycles before it changes. table 10-14 gpt2 auxiliary timer (counter mode) input edge selection t5i triggering edge for counter increment/decrement x 0 0 none. counter t5 is disabled 0 0 1 positive transition (rising edge) on t5in 0 1 0 negative transition (falling edge) on t5in 0 1 1 any transition (rising or falling edge) on t5in 1 0 1 positive transition (rising edge) of output toggle latch t6otl 1 1 0 negative transition (falling edge) of output toggle latch t6otl 1 1 1 any transition (rising or falling edge) of output toggle latch t6otl auxiliary timer tx interrupt request txr xor 0 mux 1 txeud txude mcb02221 txud txl txin edge select up/ down x = 5
c167cs derivatives the general purpose timer units users manual 10-33 v2.0, 2000-07 timer concatenation using the toggle bit t6otl as a clock source for the auxiliary timer in counter mode concatenates the core timer t6 with the auxiliary timer. depending on which transition of t6otl is selected to clock the auxiliary timer, this concatenation forms a 32-bit or a 33-bit timer/counter. ? 32-bit timer/counter: if both a positive and a negative transition of t6otl is used to clock the auxiliary timer, this timer is clocked on every overflow/underflow of the core timer t6. thus, the two timers form a 32-bit timer. ? 33-bit timer/counter: if either a positive or a negative transition of t6otl is selected to clock the auxiliary timer, this timer is clocked on every second overflow/underflow of the core timer t6. this configuration forms a 33-bit timer (16-bit core timer + t6otl + 16-bit auxiliary timer). the count directions of the two concatenated timers are not required to be the same. this offers a wide variety of different configurations. t6 can operate in timer, gated timer or counter mode in this case. figure 10-21 concatenation of core timer t6 and auxiliary timer t5 core timer ty tyotl interrupt request tyoe tyout tyr 2 n : 1 tyl mcb02034 f cpu up/down auxiliary timer tx txr txl edge select txir interrupt request *) *) note: line only affected by over/underflows of t3, but not by software modifications of t3otl. t6out = p3.1 x = 5, y = 6 n = 2 9
c167cs derivatives the general purpose timer units users manual 10-34 v2.0, 2000-07 gpt2 capture/reload register caprel in capture mode this 16-bit register can be used as a capture register for the auxiliary timer t5. this mode is selected by setting bit t5sc = 1 in control register t5con. bit ct3 selects the external input pin capin or the input pins of timer t3 as the source for a capture trigger. either a positive, a negative, or both a positive and a negative transition at pin capin can be selected to trigger the capture function, or transitions on input t3in or input t3eud or both inputs t3in and t3eud. the active edge is controlled by bit field ci in register t5con. the same coding is used as in the two least significant bits of bit field t5i (see table 10-14 ). the maximum input frequency for the capture trigger signal at capin is f cpu / 8. to ensure that a transition of the capture trigger signal is correctly recognized, its level should be held for at least 4 f cpu cycles before it changes. figure 10-22 gpt2 register caprel in capture mode when the timer t3 capture trigger is enabled (ct3 = 1) register caprel captures the contents of t5 upon transitions of the selected input(s). these values can be used to measure t3s input signals. this is useful e.g. when t3 operates in incremental interface mode, in order to derive dynamic information (speed acceleration) from the input signals. auxiliary timer t5 edge select mcb02044b interrupt request capin ci t5sc t5clr input clock up/down interrupt request caprel register
c167cs derivatives the general purpose timer units users manual 10-35 v2.0, 2000-07 when a selected transition at the selected input pin(s) (capin, t3in, t3eud) is detected, the contents of the auxiliary timer t5 are latched into register caprel, and interrupt request flag crir is set. with the same event, timer t5 can be cleared to 0000 h . this option is controlled by bit t5clr in register t5con. if t5clr = 0, the contents of timer t5 are not affected by a capture. if t5clr = 1, timer t5 is cleared after the current timer value has been latched into register caprel. note: bit t5sc only controls whether a capture is performed or not. if t5sc = 0, the selected trigger event can still be used to clear timer t5 or to generate an interrupt request. this interrupt is controlled by the caprel interrupt control register cric. gpt2 capture/reload register caprel in reload mode this 16-bit register can be used as a reload register for the core timer t6. this mode is selected by setting bit t6sr = 1 in register t6con. the event causing a reload in this mode is an overflow or underflow of the core timer t6. when timer t6 overflows from ffff h to 0000 h (when counting up) or when it underflows from 0000 h to ffff h (when counting down), the value stored in register caprel is loaded into timer t6. this will not set the interrupt request flag crir associated with the caprel register. however, interrupt request flag t6ir will be set indicating the overflow/underflow of t6. figure 10-23 gpt2 register caprel in reload mode core timer t6 up/down interrupt request t6oe t6out input clock mcb02045 t6otl t6sr caprel register
c167cs derivatives the general purpose timer units users manual 10-36 v2.0, 2000-07 gpt2 capture/reload register caprel in capture-and-reload mode since the reload function and the capture function of register caprel can be enabled individually by bits t5sc and t6sr, the two functions can be enabled simultaneously by setting both bits. this feature can be used to generate an output frequency that is a multiple of the input frequency. figure 10-24 gpt2 register caprel in capture-and-reload mode this combined mode can be used to detect consecutive external events which may occur aperiodically, but where a finer resolution, that means, more ticks within the time between two external events is required. auxiliary timer t5 edge select mcb02046b interrupt request capin ci t5sc t5clr input clock up/down interrupt request caprel register t6otl t6oe t6out core timer t6 interrupt request input clock t6sr up/down
c167cs derivatives the general purpose timer units users manual 10-37 v2.0, 2000-07 for this purpose, the time between the external events is measured using timer t5 and the caprel register. timer t5 runs in timer mode counting up with a frequency of e.g. f cpu /32. the external events are applied to pin capin. when an external event occurs, the timer t5 contents are latched into register caprel, and timer t5 is cleared (t5clr = 1). thus, register caprel always contains the correct time between two events, measured in timer t5 increments. timer t6, which runs in timer mode counting down with a frequency of e.g. f cpu / 4, uses the value in register caprel to perform a reload on underflow. this means, the value in register caprel represents the time between two underflows of timer t6, now measured in timer t6 increments. since timer t6 runs 8 times faster than timer t5, it will underflow 8 times within the time between two external events. thus, the underflow signal of timer t6 generates 8 ticks. upon each underflow, the interrupt request flag t6ir will be set and bit t6otl will be toggled. the state of t6otl may be output on pin t6out. this signal has 8 times more transitions than the signal which is applied to pin capin. the underflow signal of timer t6 can furthermore be used to clock one or more of the timers of the capcom units, which gives the user the possibility to set compare events based on a finer resolution than that of the external events.
c167cs derivatives the general purpose timer units users manual 10-38 v2.0, 2000-07 10.2.3 interrupt control for gpt2 timers and caprel when a timer overflows from ffff h to 0000 h (when counting up), or when it underflows from 0000 h to ffff h (when counting down), its interrupt request flag (t5ir or t6ir) in register txic will be set. whenever a transition according to the selection in bit field ci is detected at pin capin, interrupt request flag crir in register cric is set. setting any request flag will cause an interrupt to the respective timer or caprel interrupt vector (t5int, t6int or crint) or trigger a pec service, if the respective interrupt enable bit (t5ie or t6ie in register txic, crie in register cric) is set. there is an interrupt control register for each of the two timers and for the caprel register. note: please refer to the general interrupt control register description for an explanation of the control fields. t5ic timer 5 intr. ctrl. reg. sfr (ff66 h /b3 h ) reset value: - - 00 h 1514131211109876543210 - t5ir t5ie ilvl glvl - - - - - - - - rwh rw rw rw t6ic timer 6 intr. ctrl. reg. sfr (ff68 h /b4 h ) reset value: - - 00 h 1514131211109876543210 - t6ir t6ie ilvl glvl - - - - - - - - rwh rw rw rw cric caprel intr. ctrl. reg. sfr (ff6a h /b5 h ) reset value: - - 00 h 1514131211109876543210 - crir crie ilvl glvl - - - - - - - - rwh rw rw rw
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-1 v2.0, 2000-07 11 the asynchronous/synchronous serial interface the asynchronous/synchronous serial interface asc0 provides serial communication between the c167cs and other microcontrollers, microprocessors or external peripherals. the asc0 supports full-duplex asynchronous communication up to 781 kbaud/ 1.03 mbaud and half-duplex synchronous communication up to 3.1/4.1 mbaud (@ 25/ 33 mhz cpu clock). in synchronous mode, data are transmitted or received synchronous to a shift clock which is generated by the c167cs. in asynchronous mode, 8- or 9-bit data transfer, parity generation, and the number of stop bits can be selected. parity, framing, and overrun error detection is provided to increase the reliability of data transfers. transmission and reception of data is double-buffered. for multiprocessor communication, a mechanism to distinguish address from data bytes is included. testing is supported by a loop-back option. a 13-bit baud rate generator provides the asc0 with a separate serial clock signal. figure 11-1 sfrs and port pins associated with asc0 e mca04376 odp3 dp3 p3 s0bg s0tbuf s0rbuf s0con s0tic s0eic ports & direction control alternate functions data registers control registers interrupt control odp3 port 3 open drain control register dp3 port 3 direction control register s0bg asc0 baud rate generator/reload reg. s0tbuf asc0 transmit buffer register s0tic asc0 transmit interrupt control register s0tbic asc0 transmit buffer interrupt ctrl. reg. p3 port 3 data register s0con asc0 control register s0rbuf asc0 receive buffer register (read only) s0ric asc0 receive interrupt control register s0eic asc0 error interrupt control register s0ric rxd0/p3.11 txd0/p3.10 s0tbic e
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-2 v2.0, 2000-07 the operating mode of the serial channel asc0 is controlled by its bitaddressable control register s0con. this register contains control bits for mode and error check selection, and status flags for error identification. s0con asc0 control register sfr (ffb0 h /d8 h ) reset value: 0000 h 1514131211109876543210 s0r s0 lb s0 brs s0 odd - s0 oe s0 fe s0 pe s0 oen s0 fen s0 pen s0 ren s0 stp s0m rw rw rw rw - rwh rwh rwh rw rw rw rwh rw rw bit function s0m asc0 mode control 000: 8-bit data synchronous operation 001: 8-bit data async. operation 010: reserved. do not use this combination! 011: 7-bit data + parity async. operation 100: 9-bit data async. operation 101: 8-bit data + wake up bit async. operation 110: reserved. do not use this combination! 111: 8-bit data + parity async. operation s0stp number of stop bits selection async. operation 0: one stop bit 1: two stop bits s0ren receiver enable bit 0: receiver disabled 1: receiver enabled (reset by hardware after reception of byte in synchronous mode) s0pen parity check enable bit async. operation 0: ignore parity 1: check parity s0fen framing check enable bit async. operation 0: ignore framing errors 1: check framing errors s0oen overrun check enable bit 0: ignore overrun errors 1: check overrun errors
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-3 v2.0, 2000-07 a transmission is started by writing to the transmit buffer register s0tbuf (via an instruction or a pec data transfer). only the number of data bits which is determined by the selected operating mode will actually be transmitted, i.e. bits written to positions 9 through 15 of register s0tbuf are always insignificant. after a transmission has been completed, the transmit buffer register is cleared to 0000 h . data transmission is double-buffered, so a new character may be written to the transmit buffer register, before the transmission of the previous character is complete. this allows the transmission of characters back-to-back without gaps. data reception is enabled by the receiver enable bit s0ren. after reception of a character has been completed, the received data and, if provided by the selected operating mode, the received parity bit can be read from the (read-only) receive buffer register s0rbuf. bits in the upper half of s0rbuf which are not valid in the selected operating mode will be read as zeros. data reception is double-buffered, so that reception of a second character may already begin before the previously received character has been read out of the receive buffer register. in all modes, receive buffer overrun error detection can be selected through bit s0pe parity error flag set by hardware on a parity error (s0pen = 1). must be reset by software. s0fe framing error flag set by hardware on a framing error (s0fen = 1). must be reset by software. s0oe overrun error flag set by hardware on an overrun error (s0oen = 1). must be reset by software. s0odd parity selection bit 0: even parity (parity bit set on odd number of 1s in data) 1: odd parity (parity bit set on even number of 1s in data) s0brs baudrate selection bit 0: divide clock by reload-value + constant (depending on mode) 1: additionally reduce serial clock to 2/3rd s0lb loopback mode enable bit 0: standard transmit/receive mode 1: loopback mode enabled s0r baudrate generator run bit 0: baudrate generator disabled (asc0 inactive) 1: baudrate generator enabled bit function
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-4 v2.0, 2000-07 s0oen. when enabled, the overrun error status flag s0oe and the error interrupt request flag s0eir will be set when the receive buffer register has not been read by the time reception of a second character is complete. the previously received character in the receive buffer is overwritten. the loop-back option (selected by bit s0lb) allows the data currently being transmitted to be received simultaneously in the receive buffer. this may be used to test serial communication routines at an early stage without having to provide an external network. in loop-back mode the alternate input/output functions of the port 3 pins are not necessary. note: serial data transmission or reception is only possible when the baud rate generator run bit s0r is set to 1. otherwise the serial interface is idle. do not program the mode control field s0m in register s0con to one of the reserved combinations to avoid unpredictable behavior of the serial interface.
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-5 v2.0, 2000-07 11.1 asynchronous operation asynchronous mode supports full-duplex communication, where both transmitter and receiver use the same data frame format and the same baud rate. data is transmitted on pin txd0 and received on pin rxd0. these signals are alternate port functions. figure 11-2 asynchronous mode of serial channel asc0 asynchronous data frames 8-bit data frames either consist of 8 data bits d7 d0 (s0m = 001 b ), or of 7 data bits d6 d0 plus an automatically generated parity bit (s0m = 011 b ). parity may be odd or even, depending on bit s0odd in register s0con. an even parity bit will be set, if the modulo-2-sum of the 7 data bits is 1. an odd parity bit will be cleared in this case. parity checking is enabled via bit s0pen (always off in 8-bit data mode). the parity error flag mcb02219 reload register baud rate timer receive int. request cpu mux 2 clock s0r 16 s0rir s0tir s0eir clock serial port control shift clock receive shift register register transmit shift s0rbuf receive buffer reg. ling samp- rxd0/p3.11 txd0/p3.10 internal bus 0 1 transmit int. request error int. request s0oe s0fe s0pe s0stp s0m s0ren s0fen s0pen s0oen s0lb transmit buffer reg. s0tbuf
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-6 v2.0, 2000-07 s0pe will be set along with the error interrupt request flag, if a wrong parity bit is received. the parity bit itself will be stored in bit s0rbuf.7. figure 11-3 asynchronous 8-bit data frames 9-bit data frames either consist of 9 data bits d8 d0 (s0m = 100 b ), of 8 data bits d7 d0 plus an automatically generated parity bit (s0m = 111 b ) or of 8 data bits d7 d0 plus wake-up bit (s0m = 101 b ). parity may be odd or even, depending on bit s0odd in register s0con. an even parity bit will be set, if the modulo-2-sum of the 8 data bits is 1. an odd parity bit will be cleared in this case. parity checking is enabled via bit s0pen (always off in 9-bit data and wake-up mode). the parity error flag s0pe will be set along with the error interrupt request flag, if a wrong parity bit is received. the parity bit itself will be stored in bit s0rbuf.8. in wake-up mode received frames are only transferred to the receive buffer register, if the 9th bit (the wake-up bit) is 1. if this bit is 0, no receive interrupt request will be activated and no data will be transferred. this feature may be used to control communication in multi-processor system: when the master processor wants to transmit a block of data to one of several slaves, it first sends out an address byte which identifies the target slave. an address byte differs from a data byte in that the additional 9th bit is a 1 for an address byte and a 0 for a data byte, so no slave will be interrupted by a data byte. an address byte will interrupt all slaves (operating in 8-bit data + wake-up bit mode), so each slave can examine the 8 lsbs of the received character (the address). the addressed slave will switch to 9-bit data mode (e.g. by clearing bit s0m.0), which enables it to also receive the data bytes that will be coming (having the wake-up bit cleared). the slaves that were not being addressed remain in 8-bit data + wake-up bit mode, ignoring the following data bytes. figure 11-4 asynchronous 9-bit data frames d7 / parity mct04377 d0 (lsb) start bit d1 d2 d3 d4 d5 d6 (1st) stop bit 2nd stop bit d7 mct04378 d0 (lsb) start bit d1 d2 d3 d4 d5 d6 (1st) stop bit 2nd stop bit 9th bit data bit d8 parity wake-up bit
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-7 v2.0, 2000-07 asynchronous transmission begins at the next overflow of the divide-by-16 counter (see figure 11-4 ), provided that s0r is set and data has been loaded into s0tbuf. the transmitted data frame consists of three basic elements: ? the start bit ? the data field (8 or 9 bits, lsb first, including a parity bit, if selected) ? the delimiter (1 or 2 stop bits) data transmission is double buffered. when the transmitter is idle, the transmit data loaded into s0tbuf is immediately moved to the transmit shift register thus freeing s0tbuf for the next data to be sent. this is indicated by the transmit buffer interrupt request flag s0tbir being set. s0tbuf may now be loaded with the next data, while transmission of the previous one is still going on. the transmit interrupt request flag s0tir will be set before the last bit of a frame is transmitted, i.e. before the first or the second stop bit is shifted out of the transmit shift register. the transmitter output pin txd0 must be configured for alternate data output, i.e. the respective port output latch and the direction latch must be 1. asynchronous reception is initiated by a falling edge (1-to-0 transition) on pin rxd0, provided that bits s0r and s0ren are set. the receive data input pin rxd0 is sampled at 16 times the rate of the selected baud rate. a majority decision of the 7th, 8th and 9th sample determines the effective bit value. this avoids erroneous results that may be caused by noise. if the detected value is not a 0 when the start bit is sampled, the receive circuit is reset and waits for the next 1-to-0 transition at pin rxd0. if the start bit proves valid, the receive circuit continues sampling and shifts the incoming data frame into the receive shift register. when the last stop bit has been received, the content of the receive shift register is transferred to the receive data buffer register s0rbuf. simultaneously, the receive interrupt request flag s0rir is set after the 9th sample in the last stop bit time slot (as programmed), regardless whether valid stop bits have been received or not. the receive circuit then waits for the next start bit (1-to-0 transition) at the receive data input pin. the receiver input pin rxd0 must be configured for input, i.e. the respective direction latch must be 0. asynchronous reception is stopped by clearing bit s0ren. a currently received frame is completed including the generation of the receive interrupt request and an error interrupt request, if appropriate. start bits that follow this frame will not be recognized. note: in wake-up mode received frames are only transferred to the receive buffer register, if the 9th bit (the wake-up bit) is 1. if this bit is 0, no receive interrupt request will be activated and no data will be transferred.
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-8 v2.0, 2000-07 11.2 synchronous operation synchronous mode supports half-duplex communication, basically for simple io expansion via shift registers. data is transmitted and received via pin rxd0, while pin txd0 outputs the shift clock. these signals are alternate port functions. synchronous mode is selected with s0m = 000 b . 8 data bits are transmitted or received synchronous to a shift clock generated by the internal baud rate generator. the shift clock is only active as long as data bits are transmitted or received. figure 11-5 synchronous mode of serial channel asc0 mcb02220 reload register baud rate timer receive int. request mux 2 clock clock serial port control shift clock receive shift register receive buffer reg. txd0/p3.10 internal bus 0 1 transmit int. request error int. request s0oe s0m = 000b s0ren s0oen s0lb 4 rxd0/p3.11 receive transmit cpu s0r s0rir s0tir s0eir transmit shift register transmit buffer reg. s0tbuf s0rbuf
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-9 v2.0, 2000-07 synchronous transmission begins within 4 state times after data has been loaded into s0tbuf, provided that s0r is set and s0ren = 0 (half-duplex, no reception). data transmission is double buffered. when the transmitter is idle, the transmit data loaded into s0tbuf is immediately moved to the transmit shift register thus freeing s0tbuf for the next data to be sent. this is indicated by the transmit buffer interrupt request flag s0tbir being set. s0tbuf may now be loaded with the next data, while transmission of the previous one is still going on. the data bits are transmitted synchronous with the shift clock. after the bit time for the 8th data bit, both pins txd0 and rxd0 will go high, the transmit interrupt request flag s0tir is set, and serial data transmission stops. pin txd0 must be configured for alternate data output, i.e. the respective port output latch and the direction latch must be 1, in order to provide the shift clock. pin rxd0 must also be configured for output (output/direction latch = 1) during transmission. synchronous reception is initiated by setting bit s0ren = 1. if bit s0r = 1, the data applied at pin rxd0 are clocked into the receive shift register synchronous to the clock which is output at pin txd0. after the 8th bit has been shifted in, the content of the receive shift register is transferred to the receive data buffer s0rbuf, the receive interrupt request flag s0rir is set, the receiver enable bit s0ren is reset, and serial data reception stops. pin txd0 must be configured for alternate data output, i.e. the respective port output latch and the direction latch must be 1, in order to provide the shift clock. pin rxd0 must be configured as alternate data input, i.e. the respective direction latch must be 0. synchronous reception is stopped by clearing bit s0ren. a currently received byte is completed including the generation of the receive interrupt request and an error interrupt request, if appropriate. writing to the transmit buffer register while a reception is in progress has no effect on reception and will not start a transmission. if a previously received byte has not been read out of the receive buffer register at the time the reception of the next byte is complete, both the error interrupt request flag s0eir and the overrun error status flag s0oe will be set, provided the overrun check has been enabled by bit s0oen.
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-10 v2.0, 2000-07 11.3 hardware error detection capabilities to improve the safety of serial data exchange, the serial channel asc0 provides an error interrupt request flag, which indicates the presence of an error, and three (selectable) error status flags in register s0con, which indicate which error has been detected during reception. upon completion of a reception, the error interrupt request flag s0eir will be set simultaneously with the receive interrupt request flag s0rir, if one or more of the following conditions are met: ? if the framing error detection enable bit s0fen is set and any of the expected stop bits is not high, the framing error flag s0fe is set, indicating that the error interrupt request is due to a framing error (asynchronous mode only). ? if the parity error detection enable bit s0pen is set in the modes where a parity bit is received, and the parity check on the received data bits proves false, the parity error flag s0pe is set, indicating that the error interrupt request is due to a parity error (asynchronous mode only). ? if the overrun error detection enable bit s0oen is set and the last character received was not read out of the receive buffer by software or pec transfer at the time the reception of a new frame is complete, the overrun error flag s0oe is set indicating that the error interrupt request is due to an overrun error (asynchronous and synchronous mode).
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-11 v2.0, 2000-07 11.4 asc0 baud rate generation the serial channel asc0 has its own dedicated 13-bit baud rate generator with 13-bit reload capability, allowing baud rate generation independent of the gpt timers. the baud rate generator is clocked with the cpu clock divided by 2 ( f cpu /2). the timer is counting downwards and can be started or stopped through the baud rate generator run bit s0r in register s0con. each underflow of the timer provides one clock pulse to the serial channel. the timer is reloaded with the value stored in its 13-bit reload register each time it underflows. the resulting clock is again divided according to the operating mode and controlled by the baudrate selection bit s0brs. if s0brs = 1, the clock signal is additionally divided to 2/3rd of its frequency (see formulas and table). so the baud rate of asc0 is determined by the cpu clock, the reload value, the value of s0brs and the operating mode (asynchronous or synchronous). register s0bg is the dual-function baud rate generator/reload register. reading s0bg returns the content of the timer (bits 15 13 return zero), while writing to s0bg always updates the reload register (bits 15 13 are insiginificant). an auto-reload of the timer with the content of the reload register is performed each time s0bg is written to. however, if s0r = 0 at the time the write operation to s0bg is performed, the timer will not be reloaded until the first instruction cycle after s0r = 1. asynchronous mode baud rates for asynchronous operation, the baud rate generator provides a clock with 16 times the rate of the established baud rate. every received bit is sampled at the 7th, 8th and 9th cycle of this clock. the baud rate for asynchronous operation of serial channel asc0 and the required reload value for a given baudrate can be determined by the following formulas: represents the content of the reload register, taken as unsigned 13-bit integer, represents the value of bit s0brs (i.e. 0 or 1), taken as integer. the tables below list various commonly used baud rates together with the required reload values and the deviation errors compared to the intended baudrate for a number of cpu frequencies. note: the deviation errors given in the tables below are rounded. using a baudrate crystal (e.g. 18.432 mhz) will provide correct baudrates without deviation errors. b async = f cpu 16 (2 + ) ( + 1) s0brl = ( f cpu 16 (2 + ) b async ) C 1
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-12 v2.0, 2000-07 table 11-1 asc0 asynchronous baudrate generation for f cpu = 16 mhz baud rate s0brs = 0 s0brs = 1 deviation error reload value deviation error reload value 500 kbaud 0.0% 0000 h CC 19.2 kbaud + 0.2%/ C 3.5% 0019 h /001a h + 2.1%/ C 3.5% 0010 h /0011 h 9600 baud + 0.2%/ C 1.7% 0033 h /0034 h + 2.1%/ C 0.8% 0021 h /0022 h 4800 baud + 0.2%/ C 0.8% 0067 h /0068 h + 0.6%/ C 0.8% 0044 h /0045 h 2400 baud + 0.2%/ C 0.3% 00cf h /00d0 h + 0.6%/ C 0.1% 0089 h /008a h 1200 baud + 0.4%/ C 0.1% 019f h /01a0 h + 0.3%/ C 0.1% 0114 h /0115 h 600 baud + 0.0%/ C 0.1% 0340 h /0341 h + 0.1%/ C 0.1% 022a h /022b h 61 baud + 0.1% 1fff h + 0.0%/ C 0.0% 115b h /115c h 40 baud C C + 1.7% 1fff h table 11-2 asc0 asynchronous baudrate generation for f cpu = 20 mhz baud rate s0brs = 0 s0brs = 1 deviation error reload value deviation error reload value 625 kbaud 0.0% 0000 h CC 19.2 kbaud + 1.7%/ C 1.4% 001f h /0020 h + 3.3%/ C 1.4% 0014 h /0015 h 9600 baud + 0.2%/ C 1.4% 0040 h /0041 h + 1.0%/ C 1.4% 002a h /002b h 4800 baud + 0.2%/ C 0.6% 0081 h /0082 h + 1.0%/ C 0.2% 0055 h /0056 h 2400 baud + 0.2%/ C 0.2% 0103 h /0104 h + 0.4%/ C 0.2% 00ac h /00ad h 1200 baud + 0.2%/ C 0.4% 0207 h /0208 h + 0.1%/ C 0.2% 015a h /015b h 600 baud + 0.1%/ C 0.0% 0410 h /0411 h + 0.1%/ C 0.1% 02b5 h /02b6 h 75 baud + 1.7% 1fff h + 0.0%/ C 0.0% 15b2 h /15b3 h 50 baud C C + 1.7% 1fff h
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-13 v2.0, 2000-07 table 11-3 asc0 asynchronous baudrate generation for f cpu = 25 mhz baud rate s0brs = 0 s0brs = 1 deviation error reload value deviation error reload value 781 kbaud + 0.2% 0000 h CC 19.2 kbaud + 1.7%/ C 0.8% 0027 h /0028 h + 0.5%/ C 3.1% 001a h /001b h 9600 baud + 0.5%/ C 0.8% 0050 h /0051 h + 0.5%/ C 1.4% 0035 h /0036 h 4800 baud + 0.5%/ C 0.2% 00a1 h /00a2 h + 0.5%/ C 0.5% 006b h /006c h 2400 baud + 0.2%/ C 0.2% 0145 h /0146 h + 0.0%/ C 0.5% 00d8 h /00d9 h 1200 baud + 0.0%/ C 0.2% 028a h /028b h + 0.0%/ C 0.2% 01b1 h /01b2 h 600 baud + 0.0%/ C 0.1% 0515 h /0516 h + 0.0%/ C 0.1% 0363 h /0364 h 95 baud + 0.4% 1fff h + 0.0%/ C 0.0% 1569 h /156a h 63 baud C C + 1.0% 1fff h table 11-4 asc0 asynchronous baudrate generation for f cpu = 33 mhz baud rate s0brs = 0 s0brs = 1 deviation error reload value deviation error reload value 1.031 mbaud 0.0% 0000 h CC 19.2 kbaud + 1.3%/ C 0.5% 0034 h /0035 h + 2.3%/ C 0.5% 0022 h /0023 h 9600 baud + 0.4%/ C 0.5% 006a h /006b h + 0.9%/ C 0.5% 0046 h /0047 h 4800 baud + 0.4%/ C 0.1% 00d5 h /00d6 h + 0.2%/ C 0.5% 008e h /008f h 2400 baud + 0.2%/ C 0.1% 01ac h /01ad h + 0.2%/ C 0.2% 011d h /011e h 1200 baud + 0.0%/ C 0.1% 035a h /035b h + 0.2%/ C 0.0% 023b h /023c h 600 baud + 0.0%/ C 0.0% 06b5 h /06b6 h + 0.1%/ C 0.0% 0478 h /0479 h 125 baud + 7.1% 1fff h 0.0% 157c h 84 baud C C C 0.9% 1fff h
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-14 v2.0, 2000-07 synchronous mode baud rates for synchronous operation, the baud rate generator provides a clock with 4 times the rate of the established baud rate. the baud rate for synchronous operation of serial channel asc0 can be determined by the following formula: represents the content of the reload register, taken as unsigned 13-bit integers, represents the value of bit s0brs (i.e. 0 or 1), taken as integer. table 11-5 gives the limit baudrates depending on the cpu clock frequency and bit s0brs. table 11-5 asc0 synchronous baudrate generation cpu clock f cpu s0brs = 0 s0brs = 1 min. baudrate max. baudrate min. baudrate max. baudrate 16 mhz 244 baud 2.000 mbaud 162 baud 1.333 mbaud 20 mhz 305 baud 2.500 mbaud 203 baud 1.666 mbaud 25 mhz 381 baud 3.125 mbaud 254 baud 2.083 mbaud 33 mhz 504 baud 4.125 mbaud 336 baud 2.750 mbaud b sync = s0brl = ( 4 (2 + ) b sync f cpu f cpu ) C 1 4 (2 + ) ( + 1)
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-15 v2.0, 2000-07 11.5 asc0 interrupt control four bit addressable interrupt control registers are provided for serial channel asc0. register s0tic controls the transmit interrupt, s0tbic controls the transmit buffer interrupt, s0ric controls the receive interrupt and s0eic controls the error interrupt of serial channel asc0. each interrupt source also has its own dedicated interrupt vector. s0tint is the transmit interrupt vector, s0tbint is the transmit buffer interrupt vector, s0rint is the receive interrupt vector, and s0eint is the error interrupt vector. the cause of an error interrupt request (framing, parity, overrun error) can be identified by the error status flags in control register s0con. note: in contrast to the error interrupt request flag s0eir, the error status flags s0fe/ s0pe/s0oe are not reset automatically upon entry into the error interrupt service routine, but must be cleared by software. s0tic asc0 tx intr. ctrl. reg. sfr (ff6c h /b6 h ) reset value: - - 00 h 1514131211109876543210 - s0 tir s0 tie ilvl glvl -------- rwh rw rw rw s0tbic asc0 tx buf. intr. ctrl. reg. sfr (ff9c h /ce h ) reset value: - - 00 h 1514131211109876543210 - s0 tbir s0 tbie ilvl glvl -------- rwh rw rw rw s0ric asc0 rx intr. ctrl. reg. sfr (ff6e h /b7 h ) reset value: - - 00 h 1514131211109876543210 - s0 rir s0 rie ilvl glvl -------- rwh rw rw rw
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-16 v2.0, 2000-07 note: please refer to the general interrupt control register description for an explanation of the control fields. using the asc0 interrupts for normal operation (i.e. besides the error interrupt) the asc0 provides three interrupt requests to control data exchange via this serial channel: ? s0tbir is activated when data is moved from s0tbuf to the transmit shift register. ? s0tir is activated before the last bit of an asynchronous frame is transmitted, or after the last bit of a synchronous frame has been transmitted. ? s0rir is activated when the received frame is moved to s0rbuf. while the task of the receive interrupt handler is quite clear, the transmitter is serviced by two interrupt handlers. this provides advantages for the servicing software. for single transfers is sufficient to use the transmitter interrupt (s0tir), which indicates that the previously loaded data has been transmitted, except for the last bit of an asynchronous frame. for multiple back-to-back transfers it is necessary to load the following piece of data at last until the time the last bit of the previous frame has been transmitted. in asynchronous mode this leaves just one bit-time for the handler to respond to the transmitter interrupt request, in synchronous mode it is impossible at all. using the transmit buffer interrupt (s0tbir) to reload transmit data gives the time to transmit a complete frame for the service routine, as s0tbuf may be reloaded while the previous data is still being transmitted. s0eic asc0 error intr. ctrl. reg. sfr (ff70 h /b8 h ) reset value: - - 00 h 1514131211109876543210 - s0 eir s0 eie ilvl glvl -------- rwh rw rw rw
c167cs derivatives the asynchronous/synchronous serial interface users manual 11-17 v2.0, 2000-07 figure 11-6 asc0 interrupt generation as shown in figure 11-6 , s0tbir is an early trigger for the reload routine, while s0tir indicates the completed transmission. software using handshake therefore should rely on s0tir at the end of a data block to make sure that all data has really been transmitted. mct04379 start stop start stop start stop idle idle s0rir s0tbir s0tir s0tbir s0tir s0tbir s0rir s0rir asynchronous mode idle idle s0rir s0tbir s0tir s0tbir s0tir s0tbir s0rir s0rir synchronous mode s0tir s0tir
c167cs derivatives the high-speed synchronous serial interface users manual 12-1 v2.0, 2000-07 12 the high-speed synchronous serial interface the high-speed synchronous serial interface ssc provides flexible high-speed serial communication between the c167cs and other microcontrollers, microprocessors or external peripherals. the ssc supports full-duplex and half-duplex synchronous communication up to 6.25/ 8.25 mbaud (@ 25/33 mhz cpu clock). the serial clock signal can be generated by the ssc itself (master mode) or be received from an external master (slave mode). data width, shift direction, clock polarity and phase are programmable. this allows communication with spi-compatible devices. transmission and reception of data is double-buffered. a 16-bit baud rate generator provides the ssc with a separate serial clock signal. the high-speed synchronous serial interface can be configured in a very flexible way, so it can be used with other synchronous serial interfaces (e.g. the asc0 in synchronous mode), serve for master/slave or multimaster interconnections or operate compatible with the popular spi interface. so it can be used to communicate with shift registers (io expansion), peripherals (e.g. eeproms etc.) or other controllers (networking). the ssc supports half-duplex and full-duplex communication. data is transmitted or received on pins mtsr/p3.9 (master transmit/slave receive) and mrst/p3.8 (master receive/ slave transmit). the clock signal is output or input on pin sclk/p3.13. these pins are alternate functions of port 3 pins. figure 12-1 sfrs and port pins associated with the ssc e mca04380 odp3 dp3 p3 sscbr ssctb sscrb ssccon ssctic ssceic ports & direction control alternate functions data registers control registers interrupt control odp3 port 3 open drain control register dp3 port 3 direction control register sscbr ssc baud rate generator/reload reg. ssctb ssc transmit buffer register ssctic ssc transmit interrupt control register p3 port 3 data register ssccon ssc control register sscrb ssc receive buffer register sscric ssc receive interrupt control register ssceic ssc error interrupt control register sscric sclk/p3.13 mtsr/p3.9 mrst/p3.8 e e e
c167cs derivatives the high-speed synchronous serial interface users manual 12-2 v2.0, 2000-07 figure 12-2 synchronous serial channel ssc block diagram the operating mode of the serial channel ssc is controlled by its bit-addressable control register ssccon. this register serves for two purposes: ? during programming (ssc disabled by sscen = 0) it provides access to a set of control bits, ? during operation (ssc enabled by sscen = 1) it provides access to a set of status flags. register ssccon is shown below in each of the two modes. ssccon ssc control reg. (pr.m.) sfr (ffb2 h /d9 h ) reset value: 0000 h 1514131211109876543210 ssc en = 0 ssc ms - ssc ar en ssc ben ssc pen ssc ren ssc ten - ssc po ssc ph ssc hb sscbm rw rw - rw rw rw rw rw rw rw rw rw rw mcb01957 receive int. request transmit int. request error int.request ssc control block 16-bit shift register transmit buffer register ssctb register sscrb receive buffer pin control status control shift clock generator baud rate clock control slave clock master clock cpu clock i n t e r n a l b u s mtsr mrst sclk
c167cs derivatives the high-speed synchronous serial interface users manual 12-3 v2.0, 2000-07 bit function (programming mode, sscen = 0) sscbm ssc data width selection 0: reserved. do not use this combination 1 15: transfer data width is 2 16 bit ( + 1) sschb ssc heading control bit 0: transmit/receive lsb first 1: transmit/receive msb first sscph ssc clock phase control bit 0: shift transmit data on the leading clock edge, latch on trailing edge 1: latch receive data on leading clock edge, shift on trailing edge sscpo ssc clock polarity control bit 0: idle clock line is low, leading clock edge is low-to-high transition 1: idle clock line is high, leading clock edge is high-to-low transition sscten ssc transmit error enable bit 0: ignore transmit errors 1: check transmit errors sscren ssc receive error enable bit 0: ignore receive errors 1: check receive errors sscpen ssc phase error enable bit 0: ignore phase errors 1: check phase errors sscben ssc baudrate error enable bit 0: ignore baudrate errors 1: check baudrate errors sscaren ssc automatic reset enable bit 0: no additional action upon a baudrate error 1: the ssc is automatically reset upon a baudrate error sscms ssc master select bit 0: slave mode. operate on shift clock received via sclk 1: master mode. generate shift clock and output it via sclk sscen ssc enable bit = 0 transmission and reception disabled. access to control bits
c167cs derivatives the high-speed synchronous serial interface users manual 12-4 v2.0, 2000-07 note: the target of an access to ssccon (control bits or flags) is determined by the state of sscen prior to the access, i.e. writing c057 h to ssccon in programming mode (sscen = 0) will initialize the ssc (sscen was 0) and then turn it on (sscen = 1). when writing to ssccon, make sure that reserved locations receive zeros. ssccon ssc control reg. (op.m.) sfr (ffb2 h /d9 h ) reset value: 0000 h 1514131211109876543210 ssc en = 1 ssc ms - ssc bsy ssc be ssc pe ssc re ssc te ---- sscbc rw rw - rw rw rw rw rw - - - - r bit function (operating mode, sscen = 1) sscbc ssc bit count field shift counter is updated with every shifted bit. do not write to!!! sscte ssc transmit error flag 1: transfer starts with the slaves transmit buffer not being updated. sscre ssc receive error flag 1: reception completed before the receive buffer was read. sscpe ssc phase error flag 1: received data changes around sampling clock edge. sscbe ssc baudrate error flag 1: more than factor 2 or less than factor 0.5 between slaves actual and expected baudrate. sscbsy ssc busy flag set while a transfer is in progress. do not write to!!! sscms ssc master select bit 0: slave mode. operate on shift clock received via sclk. 1: master mode. generate shift clock and output it via sclk. sscen ssc enable bit = 1 transmission and reception enabled. access to status flags and m/s control.
c167cs derivatives the high-speed synchronous serial interface users manual 12-5 v2.0, 2000-07 the shift register of the ssc is connected to both the transmit pin and the receive pin via the pin control logic (see block diagram). transmission and reception of serial data is synchronized and takes place at the same time, i.e. the number of transmitted bits is also received. the major steps of the state machine of the ssc are controlled by the shift clock signal (see figure 12-2 ). in master mode (sscms = 1) two clocks per bit-time are generated, each upon an underflow of the baudrate counter. in slave mode (sscms = 0) one clock per bit-time is generated, when the latching edge of the external sclk signal has been detected. transmit data is written into the transmit buffer ssctb. when the contents of the buffer are moved to the shift register (immediately if no transfer is currently active) a transmit interrupt request (ssctir) is generated indicating that ssctb may be reloaded again. the busy flag sscbsy is set when the transfer starts (with the next following shift clock in master mode, immediately in slave mode). note: if no data is written to ssctb prior to a slave transfer, this transfer starts after the first latching edge of the external sclk signal is detected. no transmit interrupt is generated in this case. when the contents of the shift register are moved to the receive buffer sscrb after the programmed number of bits (2 16) have been transferred, i.e. after the last latching edge of the current transfer, a receive interrupt request (sscrir) is generated. the busy flag sscbsy is cleared at the end of the current transfer (with the next following shift clock in master mode, immediately in slave mode). when the transmit buffer is not empty at that time (in the case of continuous transfers) the busy flag is not cleared and the transfer goes on after moving data from the buffer to the shift register. software should not modify sscbsy, as this flag is hardware controlled. note: only one ssc (etc.) can be master at a given time. the transfer of serial data bits can be programmed in many respects: ? the data width can be chosen from 2 bits to 16 bits ? transfer may start with the lsb or the msb ? the shift clock may be idle low or idle high ? data bits may be shifted with the leading or trailing edge of the clock signal ? the baudrate may be set within a wide range (see baudrate generation) ? the shift clock can be generated (master) or received (slave) this allows the adaptation of the ssc to a wide range of applications, where serial data transfer is required.
c167cs derivatives the high-speed synchronous serial interface users manual 12-6 v2.0, 2000-07 the data width selection supports the transfer of frames of any length, from 2-bit characters up to 16-bit characters. starting with the lsb (sschb = 0) allows communication e.g. with asc0 devices in synchronous mode (c166 family) or 8051 like serial interfaces. starting with the msb (sschb = 1) allows operation compatible with the spi interface. regardless which data width is selected and whether the msb or the lsb is transmitted first, the transfer data is always right aligned in registers ssctb and sscrb, with the lsb of the transfer data in bit 0 of these registers. the data bits are rearranged for transfer by the internal shift register logic. the unselected bits of ssctb are ignored, the unselected bits of sscrb will be not valid and should be ignored by the receiver service routine. the clock control allows the adaptation of transmit and receive behavior of the ssc to a variety of serial interfaces. a specific clock edge (rising or falling) is used to shift out transmit data, while the other clock edge is used to latch in receive data. bit sscph selects the leading edge or the trailing edge for each function. bit sscpo selects the level of the clock line in the idle state. so for an idle-high clock the leading edge is a falling one, a 1-to-0 transition. figure 12-3 is a summary. figure 12-3 serial clock phase and polarity options mcd01960 last bit transmit data first bit latch data shift data pins mtsr/mrst serial clock sclk sscpo sscph 00 0 1 1 0 11
c167cs derivatives the high-speed synchronous serial interface users manual 12-7 v2.0, 2000-07 12.1 full-duplex operation the different devices are connected through three lines. the definition of these lines is always determined by the master: the line connected to the master s data output pin mtsr is the transmit line, the receive line is connected to its data input line mrst, and the clock line is connected to pin sclk. only the device selected for master operation generates and outputs the serial clock on pin sclk. all slaves receive this clock, so their pin sclk must be switched to input mode (dp3.13 = 0). the output of the masters shift register is connected to the external transmit line, which in turn is connected to the slaves shift register input. the output of the slaves shift register is connected to the external receive line in order to enable the master to receive the data shifted out of the slave. the external connections are hard-wired, the function and direction of these pins is determined by the master or slave operation of the individual device. note: the shift direction shown in figure 12-4 applies for msb-first operation as well as for lsb-first operation. when initializing the devices in this configuration, select one device for master operation (sscms = 1), all others must be programmed for slave operation (sscms = 0). initialization includes the operating mode of the devices ssc and also the function of the respective port lines (see chapter 12.4 ). figure 12-4 ssc full-duplex configuration mcs01963 mrst sclk device #2 slave clock shift register mtsr clock master receive transmit device #1 clock mtsr mrst sclk shift register mtsr shift register clock slave sclk mrst device #3
c167cs derivatives the high-speed synchronous serial interface users manual 12-8 v2.0, 2000-07 the data output pins mrst of all slave devices are connected together onto the one receive line in this configuration. during a transfer each slave shifts out data from its shift register. there are two ways to avoid collisions on the receive line due to different slave data: only one slave drives the line , i.e. enables the driver of its mrst pin. all the other slaves have to program their mrst pins to input. so only one slave can put its data onto the master s receive line. only receiving of data from the master is possible. the master selects the slave device from which it expects data either by separate select lines, or by sending a special command to this slave. the selected slave then switches its mrst line to output, until it gets a deselection signal or command. the slaves use open drain output on mrst . this forms a wired-and connection. the receive line needs an external pullup in this case. corruption of the data on the receive line sent by the selected slave is avoided, when all slaves which are not selected for transmission to the master only send ones (1). since this high level is not actively driven onto the line, but only held through the pullup device, the selected slave can pull this line actively to a low level when transmitting a zero bit. the master selects the slave device from which it expects data either by separate select lines, or by sending a special command to this slave. after performing all necessary initializations of the ssc, the serial interfaces can be enabled. for a master device, the alternate clock line will now go to its programmed polarity. the alternate data line will go to either 0 or 1, until the first transfer will start. when the serial interfaces are enabled, the master device can initiate the first data transfer by writing the transmit data into register ssctb. this value is copied into the shift register (which is assumed to be empty at this time), and the selected first bit of the transmit data will be placed onto the mtsr line on the next clock from the baudrate generator (transmission only starts, if sscen = 1). depending on the selected clock phase, also a clock pulse will be generated on the sclk line. with the opposite clock edge the master at the same time latches and shifts in the data detected at its input line mrst. this exchanges the transmit data with the receive data. since the clock line is connected to all slaves, their shift registers will be shifted synchronously with the masters shift register, shifting out the data contained in the registers, and shifting in the data detected at the input line. after the preprogrammed number of clock pulses (via the data width selection) the data transmitted by the master is contained in all slaves shift registers, while the masters shift register holds the data of the selected slave. in the master and all slaves the content of the shift register is copied into the receive buffer sscrb and the receive interrupt flag sscrir is set. a slave device will immediately output the selected first bit (msb or lsb of the transfer data) at pin mrst, when the content of the transmit buffer is copied into the slaves shift register. it will not wait for the next clock from the baudrate generator, as the master does. the reason for this is that, depending on the selected clock phase, the first clock
c167cs derivatives the high-speed synchronous serial interface users manual 12-9 v2.0, 2000-07 edge generated by the master may be already used to clock in the first data bit. so the slaves first data bit must already be valid at this time. note: on the ssc always a transmission and a reception takes place at the same time, regardless whether valid data has been transmitted or received. this is different e.g. from asynchronous reception on asc0. the initialization of the sclk pin on the master requires some attention in order to avoid undesired clock transitions, which may disturb the other receivers. the state of the internal alternate output lines is 1 as long as the ssc is disabled. this alternate output signal is anded with the respective port line output latch. enabling the ssc with an idle- low clock (sscpo = 0) will drive the alternate data output and (via the and) the port pin sclk immediately low. to avoid this, use the following sequence: ? select the clock idle level (sscpo = x) ? load the port output latch with the desired clock idle level (p3.13 = x) ? switch the pin to output (dp3.13 = 1) ? enable the ssc (sscen = 1) ? if sscpo = 0: enable alternate data output (p3.13 = 1) the same mechanism as for selecting a slave for transmission (separate select lines or special commands) may also be used to move the role of the master to another device in the network. in this case the previous master and the future master (previous slave) will have to toggle their operating mode (sscms) and the direction of their port pins (see description above).
c167cs derivatives the high-speed synchronous serial interface users manual 12-10 v2.0, 2000-07 12.2 half-duplex operation in a half duplex configuration only one data line is necessary for both receiving and transmitting of data. the data exchange line is connected to both pins mtsr and mrst of each device, the clock line is connected to the sclk pin. the master device controls the data transfer by generating the shift clock, while the slave devices receive it. due to the fact that all transmit and receive pins are connected to the one data exchange line, serial data may be moved between arbitrary stations. similar to full duplex mode there are two ways to avoid collisions on the data exchange line: ? only the transmitting device may enable its transmit pin driver ? the non-transmitting devices use open drain output and only send ones since the data inputs and outputs are connected together, a transmitting device will clock in its own data at the input pin (mrst for a master device, mtsr for a slave). by these means any corruptions on the common data exchange line are detected, where the received data is not equal to the transmitted data. figure 12-5 ssc half-duplex configuration mcs01965 common transmit/ receive line mrst sclk device #2 slave clock shift register mtsr clock master device #1 clock mtsr mrst sclk shift register shift register clock slave device #3 sclk mtsr mrst
c167cs derivatives the high-speed synchronous serial interface users manual 12-11 v2.0, 2000-07 12.3 continuous transfers when the transmit interrupt request flag is set, it indicates that the transmit buffer ssctb is empty and ready to be loaded with the next transmit data. if ssctb has been reloaded by the time the current transmission is finished, the data is immediately transferred to the shift register and the next transmission will start without any additional delay. on the data line there is no gap between the two successive frames. e.g. two byte transfers would look the same as one word transfer. this feature can be used to interface with devices which can operate with or require more than 16 data bits per transfer. it is just a matter of software, how long a total data frame length can be. this option can also be used e.g. to interface to byte-wide and word-wide devices on the same serial bus. note: of course, this can only happen in multiples of the selected basic data width, since it would require disabling/enabling of the ssc to reprogram the basic data width on-the-fly.
c167cs derivatives the high-speed synchronous serial interface users manual 12-12 v2.0, 2000-07 12.4 port control the ssc uses three pins of port 3 to communicate with the external world. pin p3.13/ sclk serves as the clock line, while pins p3.8/mrst (master receive/slave transmit) and p3.9/mtsr (master transmit/slave receive) serve as the serial data input/output lines.the operation of these pins depends on the selected operating mode (master or slave). in order to enable the alternate output functions of these pins instead of the general purpose io operation, the respective port latches have to be set to 1, since the port latch outputs and the alternate output lines are anded. when an alternate data output line is not used (function disabled), it is held at a high level, allowing io operations via the port latch. the direction of the port lines depends on the operating mode. the ssc will automatically use the correct alternate input or output line of the ports when switching modes. the direction of the pins, however, must be programmed by the user, as shown in the tables. using the open drain output feature helps to avoid bus contention problems and reduces the need for hardwired hand-shaking or slave select lines. in this case it is not always necessary to switch the direction of a port pin. table 12-1 summarizes the required values for the different modes and pins. note: in table 12-1 , an x means that the actual value is irrelevant in the respective mode, however, it is recommended to set these bits to 1, so they are already in the correct state when switching between master and slave mode. table 12-1 ssc port control pin master mode slave mode function port latch direction function port latch direction sclk serial clock output p3.13 = 1 dp3.13 = 1 serial clock input p3.13 = x dp3.13 = 0 mtsr serial data output p3.9 = 1 dp3.9 = 1 serial data input p3.9 = x dp3.9 = 0 mrst serial data input p3.8 = x dp3.8 = 0 serial data output p3.8 = 1 dp3.8 = 1
c167cs derivatives the high-speed synchronous serial interface users manual 12-13 v2.0, 2000-07 12.5 baud rate generation the serial channel ssc has its own dedicated 16-bit baud rate generator with 16-bit reload capability, permitting baud rate generation independent from the timers. the baud rate generator is clocked with the cpu clock divided by 2 ( f cpu / 2). the timer is counting downwards and can be started or stopped through the global enable bit sscen in register ssccon. register sscbr is the dual-function baud rate generator/reload register. reading sscbr, while the ssc is enabled, returns the content of the timer. reading sscbr, while the ssc is disabled, returns the programmed reload value. in this mode the desired reload value can be written to sscbr. note: never write to sscbr, while the ssc is enabled. the formulas below calculate either the resulting baud rate for a given reload value, or the required reload value for a given baudrate: represents the content of the reload register, taken as an unsigned 16-bit integer. table 12-2 list some possible baud rates together with the required reload values and the resulting bit times, for different cpu clock frequencies. table 12-2 ssc bit-time calculation bit-time for f cpu = reload val. (sscbr) 16 mhz 20 mhz 25 mhz 33 mhz reserved. sscbr must be > 0. 0000 h 250 ns 200 ns 160 ns 121 ns 0001 h 375 ns 300 ns 240 ns 182 ns 0002 h 500 ns 400 ns 320 ns 242 ns 0003 h 625 ns 500 ns 400 ns 303 ns 0004 h 1.00 m s 800 ns 640 ns 485 ns 0007 h 1.25 m s1 m s 800 ns 606 ns 0009 h 10 m s8 m s6.4 m s4.8 m s 004f h 12.5 m s10 m s8 m s6.1 m s 0063 h 15.6 m s12.5 m s10 m s7.6 m s 007c h 20.6 m s16.5 m s13.2 m s10 m s00a4 h b ssc = f cpu 2 ( + 1) sscbr = ( f cpu 2 baudrate ssc ) C 1 ,
c167cs derivatives the high-speed synchronous serial interface users manual 12-14 v2.0, 2000-07 1ms 800 m s640 m s 485 m s1f3f h 1.25 ms 1 ms 800 m s 606 m s 270f h 1.56 ms 1.25 ms 1 ms 758 m s30d3 h 8.2 ms 6.6 ms 5.2 ms 4.0 ms ffff h table 12-3 ssc baudrate calculation baud rate for f cpu = reload val. (sscbr) 16 mhz 20 mhz 25 mhz 33 mhz reserved. sscbr must be > 0. 0000 h 4.00 mbaud 5.00 mbaud 6.25 mbaud 8.25 mbaud 0001 h 2.67 mbaud 3.33 mbaud 4.17 mbaud 5.50 mbaud 0002 h 2.00 mbaud 2.50 mbaud 3.13 mbaud 4.13 mbaud 0003 h 1.60 mbaud 2.00 mbaud 2.50 mbaud 3.30 mbaud 0004 h 1.00 mbaud 1.25 mbaud 1.56 mbaud 2.06 mbaud 0007 h 800 kbaud 1.0 mbaud 1.25 mbaud 1.65 mbaud 0009 h 100 kbaud 125 kbaud 156 kbaud 206 kbaud 004f h 80 kbaud 100 kbaud 125 kbaud 165 kbaud 0063 h 64 kbaud 80 kbaud 100 kbaud 132 kbaud 007c h 48.5 kbaud 60.6 kbaud 75.8 kbaud 100 kbaud 00a4 h 1.0 kbaud 1.25 kbaud 1.56 kbaud 2.06 kbaud 1f3f h 800 baud 1.0 kbaud 1.25 kbaud 1.65 kbaud 270f h 640 baud 800 baud 1.0 kbaud 1.32 kbaud 30d3 h 122.1 baud 152.6 baud 190.7 baud 251.7 baud ffff h table 12-2 ssc bit-time calculation (contd) bit-time for f cpu = reload val. (sscbr) 16 mhz 20 mhz 25 mhz 33 mhz
c167cs derivatives the high-speed synchronous serial interface users manual 12-15 v2.0, 2000-07 12.6 error detection mechanisms the ssc is able to detect four different error conditions. receive error and phase error are detected in all modes, while transmit error and baudrate error only apply to slave mode. when an error is detected, the respective error flag is set. when the corresponding error enable bit is set, also an error interrupt request will be generated by setting ssceir (see figure 12-6 ). the error interrupt handler may then check the error flags to determine the cause of the error interrupt. the error flags are not reset automatically (like ssceir), but rather must be cleared by software after servicing. this allows servicing of some error conditions via interrupt, while the others may be polled by software. note: the error interrupt handler must clear the associated (enabled) errorflag(s) to prevent repeated interrupt requests. a receive error (master or slave mode) is detected, when a new data frame is completely received, but the previous data was not read out of the receive buffer register sscrb. this condition sets the error flag sscre and, when enabled via sscren, the error interrupt request flag ssceir. the old data in the receive buffer sscrb will be overwritten with the new value and is unretrievably lost. a phase error (master or slave mode) is detected, when the incoming data at pin mrst (master mode) or mtsr (slave mode), sampled with the same frequency as the cpu clock, changes between one sample before and two samples after the latching edge of the clock signal (see clock control). this condition sets the error flag sscpe and, when enabled via sscpen, the error interrupt request flag ssceir. a baud rate error (slave mode) is detected, when the incoming clock signal deviates from the programmed baud rate by more than 100%, i.e. it either is more than double or less than half the expected baud rate. this condition sets the error flag sscbe and, when enabled via sscben, the error interrupt request flag ssceir. using this error detection capability requires that the slaves baud rate generator is programmed to the same baud rate as the master device. this feature detects false additional, or missing pulses on the clock line (within a certain frame). note: if this error condition occurs and bit sscaren = 1, an automatic reset of the ssc will be performed in case of this error. this is done to reinitialize the ssc, if too few or too many clock pulses have been detected.
c167cs derivatives the high-speed synchronous serial interface users manual 12-16 v2.0, 2000-07 a transmit error (slave mode) is detected, when a transfer was initiated by the master (shift clock gets active), but the transmit buffer ssctb of the slave was not updated since the last transfer. this condition sets the error flag sscte and, when enabled via sscten, the error interrupt request flag ssceir. if a transfer starts while the transmit buffer is not updated, the slave will shift out the old contents of the shift register, which normally is the data received during the last transfer. this may lead to the corruption of the data on the transmit/receive line in half-duplex mode (open drain configuration), if this slave is not selected for transmission. this mode requires that slaves not selected for transmission only shift out ones, i.e. their transmit buffers must be loaded with ffff h prior to any transfer. note: a slave with push/pull output drivers, which is not selected for transmission, will normally have its output drivers switched. however, in order to avoid possible conflicts or misinterpretations, it is recommended to always load the slaves transmit buffer prior to any transfer. figure 12-6 ssc error interrupt control & sscten sscte transmit error register ssccon & sscren sscre receive error & sscpen sscpe phase error & sscben sscbe baudrate error 1 > C & ssceie ssceir error interrupt ssceint register ssceic mca01968
c167cs derivatives the high-speed synchronous serial interface users manual 12-17 v2.0, 2000-07 12.7 ssc interrupt control three bit addressable interrupt control registers are provided for serial channel ssc. register ssctic controls the transmit interrupt, sscric controls the receive interrupt and ssceic controls the error interrupt of serial channel ssc. each interrupt source also has its own dedicated interrupt vector. sctint is the transmit interrupt vector, scrint is the receive interrupt vector, and sceint is the error interrupt vector. the cause of an error interrupt request (receive, phase, baudrate, transmit error) can be identified by the error status flags in control register ssccon. note: in contrary to the error interrupt request flag ssceir, the error status flags sscxe are not reset automatically upon entry into the error interrupt service routine, but must be cleared by software. note: please refer to the general interrupt control register description for an explanation of the control fields. ssctic ssc transmit intr. ctrl. reg. sfr (ff72 h /b9 h ) reset value: - - 00 h 1514131211109876543210 ssc tir ssc tie ilvl glvl - - - - - - - - rw rw rw rw sscric ssc receive intr. ctrl. reg. sfr (ff74 h /ba h ) reset value: - - 00 h 1514131211109876543210 ssc rir ssc rie ilvl glvl - - - - - - - - rw rw rw rw ssceic ssc error intr. ctrl. reg. sfr (ff76 h /bb h ) reset value: - - 00 h 1514131211109876543210 ssc eir ssc eie ilvl glvl - - - - - - - - rw rw rw rw
c167cs derivatives the watchdog timer (wdt) users manual 13-1 v2.0, 2000-07 13 the watchdog timer (wdt) to allow recovery from software or hardware failure, the c167cs provides a watchdog timer. if the software fails to service this timer before an overflow occurs, an internal reset sequence will be initiated. this internal reset will also pull the rstout pin low, which also resets the peripheral hardware which might be the cause for the malfunction. when the watchdog timer is enabled and the software has been designed to service it regularly before it overflows, the watchdog timer will supervise the program execution as it only will overflow if the program does not progress properly. the watchdog timer will also time out if a software error was due to hardware related failures. this prevents the controller from malfunctioning for longer than a user-specified time. note: when the bidirectional reset is enabled also pin rstin will be pulled low for the duration of the internal reset sequence upon a software reset or a watchdog timer reset. the watchdog timer provides two registers: ? a read-only timer register that contains the current count, and ? a control register for initialization and reset source detection. figure 13-1 sfrs and port pins associated with the watchdog timer the watchdog timer is a 16-bit up counter which is clocked with the prescaled cpu clock ( f cpu ). the prescaler divides the cpu clock: ? by 2 (wdtin = 0, wdtpre = 0), or ? by 4 (wdtin = 0, wdtpre = 1), or ? by 128 (wdtin = 1, wdtpre = 0), or ? by 256 (wdtin = 1, wdtpre = 1). mca04381 wdt wdtcon reset indication pins data registers control registers rstout (deactivated by einit) rstin (bidirectional reset only)
c167cs derivatives the watchdog timer (wdt) users manual 13-2 v2.0, 2000-07 the 16-bit watchdog timer is realized as two concatenated 8-bit timers (see figure 13-2 ). the upper 8 bits of the watchdog timer can be preset to a user-programmable value via a watchdog service access in order to vary the watchdog expire time. the lower 8 bits are reset upon each service access. figure 13-2 watchdog timer block diagram mcb04470 wdt high byte wdtr mux rstout wdtpre wdt low byte wdtrel control wdt f cpu reset clear mux wdtin 2 128 2
c167cs derivatives the watchdog timer (wdt) users manual 13-3 v2.0, 2000-07 13.1 operation of the watchdog timer the current count value of the watchdog timer is contained in the watchdog timer register wdt which is a non-bitaddressable read-only register. the operation of the watchdog timer is controlled by its bitaddressable watchdog timer control register wdtcon. this register specifies the reload value for the high byte of the timer, selects the input clock prescaling factor and also provides flags that indicate the source of a reset. after any reset (except see note) the watchdog timer is enabled and starts counting up from 0000 h with the default frequency f wdt = f cpu / 2. the default input frequency may be changed to another frequency ( f wdt = f cpu / 4,128,256) by programming the prescaler (bits wdtpre and wdtin). the watchdog timer can be disabled by executing the instruction diswdt (disable watchdog timer). instruction diswdt is a protected 32-bit instruction which will only be executed during the time between a reset and execution of either the einit (end of initialization) or the srvwdt (service watchdog timer) instruction. either one of these instructions disables the execution of diswdt. note: after a hardware reset that activates the bootstrap loader the watchdog timer will be disabled. the software reset that terminates the bsl mode will then enable the wdt. when the watchdog timer is not disabled via instruction diswdt it will continue counting up, even during idle mode. if it is not serviced via the instruction srvwdt by the time the count reaches ffff h the watchdog timer will overflow and cause an internal reset. this reset will pull the external reset indication pin rstout low. the watchdog timer reset indication flag (wdtr) in register wdtcon will be set in this case. in bidirectional reset mode also pin rstin will be pulled low for the duration of the internal reset sequence and a long hardware reset will be indicated instead. a watchdog reset will also complete a running external bus cycle before starting the internal reset sequence if this bus cycle does not use ready or samples ready active (low) after the programmed waitstates. otherwise the external bus cycle will be aborted. to prevent the watchdog timer from overflowing it must be serviced periodically by the user software. the watchdog timer is serviced with the instruction srvwdt which is a protected 32-bit instruction. servicing the watchdog timer clears the low byte and reloads the high byte of the watchdog timer register wdt with the preset value from bitfield wdtrel which is the high byte of register wdtcon. servicing the watchdog timer will also reset bit wdtr. after being serviced the watchdog timer continues counting up from the value ( 2 8 ). instruction srvwdt has been encoded in such a way that the chance of unintentionally servicing the watchdog timer (e.g. by fetching and executing a bit pattern from a wrong location) is minimized. when instruction srvwdt does not match the format for
c167cs derivatives the watchdog timer (wdt) users manual 13-4 v2.0, 2000-07 protected instructions the protection fault trap will be entered, rather than the instruction be executed. note: the reset value depends on the reset source (see description below). the execution of einit clears the reset indication flags. the time period for an overflow of the watchdog timer is programmable in two ways: ? the input frequency to the watchdog timer can be selected via a prescaler controlled by bits wdtpre and wdtin in register wdtcon to be f cpu / 2, f cpu / 4, f cpu / 128, or f cpu / 256. ? the reload value wdtrel for the high byte of wdt can be programmed in register wdtcon. the period p wdt between servicing the watchdog timer and the next overflow can therefore be determined by the following formula: wdtcon wdt control register sfr (ffae h /d7 h ) reset value: 00xx h 1514131211109876543210 wdtrel wdt pre -- lhw r shw r sw r wdt r wdt in - rw - - rh rh rh rh rw bit function wdtin watchdog timer input frequency select controls the input clock prescaler. see table 13-1 . wdtr watchdog timer reset indication flag cleared by a hardware reset or by the srvwdt instruction. swr software reset indication flag shwr short hardware reset indication flag lhwr long hardware reset indication flag wdtpre watchdog timer input prescaler control controls the input clock prescaler. see table 13-1 . wdtrel watchdog timer reload value (for the high byte of wdt) p wdt = f cpu 2 (1 + + 6) (2 16 C 2 8 )
c167cs derivatives the watchdog timer (wdt) users manual 13-5 v2.0, 2000-07 table 13-1 marks the possible ranges (depending on the prescaler bits wdtpre and wdtin) for the watchdog time which can be achieved using a certain cpu clock. note: for safety reasons, the user is advised to rewrite wdtcon each time before the watchdog timer is serviced. table 13-1 watchdog time ranges cpu clock f cpu prescaler reload value in wdtrel wdt in wdt pre f wdt ff h 7f h 00 h 12 mhz 00 f cpu / 2 42.67 m s 5.50 ms 10.92 ms 01 f cpu / 4 85.33 m s 11.01 ms 21.85 ms 10 f cpu / 128 2.73 ms 352.3 ms 699.1 ms 11 f cpu / 256 5.46 ms 704.5 ms 1398 ms 16 mhz 00 f cpu / 2 32.00 m s4.13 ms8.19 ms 01 f cpu / 4 64.00 m s 8.26 ms 16.38 ms 10 f cpu / 128 2.05 ms 264.2 ms 524.3 ms 11 f cpu / 256 4.10 ms 528.4 ms 1049 ms 20 mhz 00 f cpu / 2 25.60 m s3.30 ms6.55 ms 01 f cpu / 4 51.20 m s 6.61 ms 13.11 ms 10 f cpu / 128 1.64 ms 211.4 ms 419.4 ms 11 f cpu / 256 3.28 ms 422.7 ms 838.9 ms 25 mhz 00 f cpu / 2 20.48 m s2.64 ms5.24 ms 01 f cpu / 4 40.96 m s 5.28 ms 10.49 ms 10 f cpu / 128 1.31 ms 169.1 ms 335.5 ms 11 f cpu / 256 2.62 ms 338.2 ms 671.1 ms 33 mhz 00 f cpu / 2 15.52 m s2.00 ms3.97 ms 01 f cpu / 4 31.03 m s4.00 ms7.94 ms 10 f cpu / 128 0.99 ms 128.1 ms 254.2 ms 11 f cpu / 256 1.99 ms 256.2 ms 508.4 ms
c167cs derivatives the watchdog timer (wdt) users manual 13-6 v2.0, 2000-07 13.2 reset source indication the reset indication flags in register wdtcon provide information on the source for the last reset. as the c167cs starts executing from location 000000 h after any possible reset event the initialization software may check these flags in order to determine if the recent reset event was triggered by an external hardware signal (via rstin ), by software itself or by an overflow of the watchdog timer. the initialization (and also the further operation) of the microcontroller system can thus be adapted to the respective circumstances, e.g. a special routine may verify the software integrity after a watchdog timer reset. the reset indication flags are not mutually exclusive, i.e. more than one flag may be set after reset depending on its source. table 13-2 summarizes the possible combinations: long hardware reset is indicated when the rstin input is still sampled low (active) at the end of a hardware triggered internal reset sequence. short hardware reset is indicated when the rstin input is sampled high (inactive) at the end of a hardware triggered internal reset sequence. software reset is indicated after a reset triggered by the excution of instruction srst. watchdog timer reset is indicated after a reset triggered by an overflow of the watchdog timer. note: when bidirectional reset is enabled the rstin pin is pulled low for the duration of the internal reset sequence upon any sort of reset. therefore always a long hardware reset (lhwr) will be recognized in any case. table 13-2 reset indication flag combinations event reset indication flags 1) 1) description of table entries: 1 = flag is set, 0 = flag is cleared, C = flag is not affected, * = flag is set in bidirectional reset mode, not affected otherwise. lhwr shwr swr wdtr long hardware reset1110 short hardware reset * 110 software reset ** 1 C watchdog timer reset ** 11 einit instruction 000C srvwdt instruction CCC0
c167cs derivatives the real time clock users manual 14-1 v2.0, 2000-07 14 the real time clock the real time clock (rtc) module of the c167cs basically is an independent timer chain which is clocked directly with the oscillator clock and serves for different purposes: ? system clock to determine the current time and date ? cyclic time based interrupt ? 48-bit timer for long term measurements figure 14-1 sfrs associated with the rtc module the rtc module consists of a chain of 3 divider blocks, a fixed 8:1 divider, the reloadable 16-bit timer t14 and the 32-bit rtc timer (accessible via registers rtch and rtcl). both timers count up. the clock signal for the rtc module is directly derived from the on-chip oscillator frequency (not from the cpu clock) and fed through a separate clock driver. it is therefore independent from the selected clock generation mode of the c167cs and is controlled by the clock generation circuitry. note: the rtc registers are not affected by a reset. after a power on reset, however, they are undefined. table 14-1 rtc register location within the esfr space. register name long / short address reset value notes t14 f0d2 h / 69 h uuuu h prescaler timer, generates input clock for rtc register and periodic interrupt t14rel f0d0 h / 68 h uuuu h timer reload register rtch f0d6 h / 6b h uuuu h high word of rtc register rtcl f0d4 h / 6a h uuuu h low word of rtc register mca04463 syscon2 t14rel t14 isnc control registers data registers counter registers interrupt control rtch real time clock register, high word rtcl real time clock register, low word isnc interrupt subnode control register xp3ic rtc interrupt control register xp3ic e ee rtch e rtcl e e syscon2 power management control register t14rel timer t14 reload register t14 timer t14 count register e
c167cs derivatives the real time clock users manual 14-2 v2.0, 2000-07 figure 14-2 rtc block diagram system clock operation a real time system clock can be maintained that keeps on running also during idle mode and power down mode (optionally) and represents the current time and date. this is possible as the rtc module is not effected by a reset. the maximum resolution (minimum stepwidth) for this clock information is determined by timer t14s input clock. the maximum usable timespan is achieved when t14rel is loaded with 0000 h and so t14 divides by 2 16 . cyclic interrupt generation the rtc module can generate an interrupt request whenever timer t14 overflows and is reloaded. this interrupt request may e.g. be used to provide a system time tick independent of the cpu frequency without loading the general purpose timers, or to wake up regularly from idle mode. the interrupt cycle time can be adjusted via the timer t14 reload register t14rel. please refer to rtc interrupt generation below for more details. 48-bit timer operation the concatenation of the 16-bit reload timer t14 and the 32-bit rtc timer can be regarded as a 48-bit timer which is clocked with the rtc input frequency divided by the fixed prescaler. the reload register t14rel should be cleared to get a 48-bit binary timer. however, any other reload value may be used. the maximum usable timespan is 2 48 ( ? 10 14 ) t14 input clocks, which would equal more than 100 years at an oscillator frequency of 20 mhz. mcd04432 t14rel t14 8:1 rtc f rtcl rtch interrupt request reload
c167cs derivatives the real time clock users manual 14-3 v2.0, 2000-07 rtc register access the actual value of the rtc is represented by the 3 registers t14, rtcl and rtch. as these registers are concatenated to build the rtc counter chain, internal overflows occur while the rtc is running. when reading or writing the rtc value make sure to account for such internal overflows in order to avoid reading/writing corrupted values. when reading/writing e.g. 0000 h to rtch and then accessing rtcl will produce a corrupted value as rtcl may overflow before it can be accessed. in this case, however, rtch would be 0001 h . the same precautions must be taken for t14 and t14rel. rtc interrupt generation the rtc interrupt shares the xper3 interrupt node with the pll/owd interrupt. this is controlled by the interrupt subnode control register isnc. the interrupt handler can determine the source of an interrupt request via the separate interrupt request and enable flags (see figure 14-3 ) provided in register isnc. note: if only one source is enabled no additional software check is required, of course. figure 14-3 rtc interrupt logic if t14 interrupts are to be used both stages, the interrupt node (xp3ie = 1) and the rtc subnode (rtcie = 1) must be enabled. please note that the node request bit xp3ir is automatically cleared when the interrupt handler is vectored to, while the subnode request bit rtcir must be cleared by software. mca04464 rtcie intr. enable intr. enable pllir rtcir pll/owd interrupt t14 interrupt xper3 interrupt node pllie intr. request intr. request interrupt controller register isnc register xp3ic
c167cs derivatives the real time clock users manual 14-4 v2.0, 2000-07 defining the rtc time base the reload timer t14 determines the input frequency of the rtc timer, i.e. the rtc time base, as well as the t14 interrupt cycle time. table 14-2 lists the interrupt period range and the t14 reload values (for a time base of 1 s and 1 ms) for several oscillator frequencies: increased rtc accuracy through software correction the accuracy of the c167css rtc is determined by the oscillator frequency and by the respective prescaling factor (excluding or including t14). the accuracy limit generated by the prescaler is due to the quantization of a binary counter (where the average is zero), while the accuracy limit generated by the oscillator frequency is due to the difference between ideal and real frequency (and therefore accumulates over time). the total accuracy of the rtc can be further increased via software for specific applications that demand a high time accuracy. the key to the improved accuracy is the knowledge of the exact oscillator frequency. the relation of this frequency to the expected ideal frequency is a measure for the rtcs deviation. the number n of cycles after which this deviation causes an error of 1 cycle can be easily computed. so the only action is to correct the count by 1 after each series of n cycles. this correction may be applied to the rtc register as well as to t14. also the correction may be done cyclic, e.g. within t14s interrupt service routine, or by evaluating a formula when the rtc registers are read (for this the respective last rtc value must be available somewhere). note: for the majority of applications, however, the standard accuracy provided by the rtcs structure will be more than sufficient. table 14-2 rtc interrupt periods and reload values oscillator frequency rtc interrupt period reload value a reload value b minimum maximum t14rel base t14rel base 32.768 khz aux. 244.14 m s 16.0 s f000 h 1.000 s fffc h 0.977 ms 32 khz aux. 250 m s 16.38 s f060 h 1.000 s fffc h 1.000 ms 32 khz main 8000 m s 524.29 s ff83 h 1.000 s ---- ---- 4 mhz main 64.0 m s 4.19 s c2f7 h 1.000 s fff0 h 1.024 ms 5 mhz main 51.2 m s 3.35 s b3b5 h 0.999 s ffec h 1.024 ms 8 mhz main 32.0 m s 2.10 s 85ee h 1.000 s ffe1 h 0.992 ms 10 mhz main 25.6 m s 1.68 s 676a h 0.999 s ffd9 h 0.998 ms 12 mhz main 21.3 m s 1.40 s 48e5 h 1.000 s ffd2 h 1.003 ms 16 mhz main 16.0 m s1.05 s 0bdc h 1.000 s ffc2 h 0.992 ms
c167cs derivatives the bootstrap loader users manual 15-1 v2.0, 2000-07 15 the bootstrap loader the built-in bootstrap loader of the c167cs provides a mechanism to load the startup program, which is executed after reset, via the serial interface. in this case no external memory or an internal rom/otp/flash is required for the initialization code. the bootstrap loader moves code/data into the internal ram, but it is also possible to transfer data via the serial interface into an external ram using a second level loader routine. rom memory (internal or external) is not necessary. however, it may be used to provide lookup tables or may provide core-code, i.e. a set of general purpose subroutines, e.g. for io operations, number crunching, system initialization, etc. figure 15-1 bootstrap loader sequence the bootstrap loader may be used to load the complete application software into romless systems, it may load temporary software into complete systems for testing or calibration, it may also be used to load a programming routine for flash devices. the bsl mechanism may be used for standard system startup as well as only for special occasions like system maintenance (firmware update) or end-of-line programming or testing. mct04465 rstin p0l.4 or rd rxd0 txd0 csp:ip 1) 2) 4) 3) 5) 32 bytes user software 6) int. boot rom bsl-routine 1) bsl initialization time, > 2 s @ f cpu = 20 mhz. 2) zero byte (1 start bit, eight '0' data bits, 1 stop bit), sent by host. 3) identification byte, sent by c 167cs. 4) 32 bytes of code / data, sent by host. 5) caution: txd0 is only driven a certain time after reception of the zero byte (2.5 s @ f cpu = 20 mhz) 6) internal boot rom.
c167cs derivatives the bootstrap loader users manual 15-2 v2.0, 2000-07 15.1 entering the bootstrap loader the c167cs enters bsl mode triggered by external configuration during a hardware reset: ? when pin p0l.4 is sampled low at the end of an external reset (ea = 0) ? when pin rd is sampled low at the end of an internal reset (ea = 1). in this case the built-in bootstrap loader is activated independent of the selected bus mode. the bootstrap loader code is stored in a special boot-rom, no part of the standard mask rom, otp, or flash memory area is required for this. the hardware that activates the bsl during reset may be a simple pull-down resistor on p0l.4 or rd for systems that use this feature upon every hardware reset. you may want to use a switchable solution (via jumper or an external signal) for systems that only temporarily use the bootstrap loader. figure 15-2 hardware provisions to activate the bsl the asc0 receiver is only enabled after the identification byte has been transmitted. a half duplex connection to the host is therefore sufficient to feed the bsl. note: the proper reset configuration for bsl mode requires more pins to be driven besides p0l.4 or rd . for an external reset (ea = 0) bitfield smod must be configured as 1011 b (see section section 20.4.1 ). for an internal reset (ea = 1) pin ale must be driven to a defined level, e.g. ale = 0 for the standard bootstrap loader (see section section 20.4.2 ). mca04466 rd p0l.4 ext. signal start boot ~2 k proposal for internal reset (ea = '1') rd p0l.4 ext. signal start boot ~8 k proposal for internal reset (ea = '0') rd p0l.4 ext. signal start boot proposal for combined circuitry ~2 k ~8 k
c167cs derivatives the bootstrap loader users manual 15-3 v2.0, 2000-07 initial state in bsl mode after entering bsl mode and the respective initialization 1) the c167cs scans the rxd0 line to receive a zero byte, i.e. one start bit, eight 0 data bits and one stop bit. from the duration of this zero byte it calculates the corresponding baudrate factor with respect to the current cpu clock, initializes the serial interface asc0 accordingly and switches pin txd0 to output. using this baudrate, an identification byte is returned to the host that provides the loaded data. this identification byte identifies the device to be booted. the following codes are defined: 55 h : 8xc166. a5 h : previous versions of the c167 (obsolete). b5 h : previous versions of the c165. c5 h : c167 derivatives. d5 h : all devices equipped with identification registers. note: the identification byte d5 h does not directly identify a specific derivative. this information can in this case be obtained from the identification registers. when the c167cs has entered bsl mode, the following configuration is automatically set (values that deviate from the normal reset values, are marked ): watchdog timer: disabled register stkun: fc00 h context pointer cp: fa00 h register stkov: f600 h stack pointer sp: fa40 h register buscon0: acc. to startup config. register s0con: 8011 h p3.10/txd0: 1 register s0bg: acc. to 00 byte dp3.10: 1 other than after a normal reset the watchdog timer is disabled, so the bootstrap loading sequence is not time limited. pin txd0 is configured as output, so the c167cs can return the identification byte. note: even if the internal rom/otp/flash is enabled, no code can be executed out of it while the c167cs is in bsl mode. 1) the external host should not send the zero byte before the end of the bsl initialization time (see figure 15-1 ) to make sure that it is correctly received.
c167cs derivatives the bootstrap loader users manual 15-4 v2.0, 2000-07 memory configuration after reset the configuration (i.e. the accessibility) of the c167css memory areas after reset in bootstrap loader mode differs from the standard case. pin ea does not select the code source in bsl mode, and accesses to the internal code memory are partly redirected, while the c167cs is in bsl mode (see table 15-1 ). all code fetches are made from the special boot-rom, while data accesses read from the internal code memory. data accesses will return undefined values on romless devices. note: the code in the boot-rom is not an invariant feature of the c167cs. user software should not try to execute code from the internal rom area while the bsl mode is still active, as these fetches will be redirected to the boot-rom. the boot-rom will also move to segment 1, when the internal rom area is mapped to segment 1. table 15-1 bsl memory configurations bsl mode active yes yes no ea pin high low acc. to application code fetch from internal rom area boot-rom access boot-rom access user rom access data fetch from internal rom area user rom access user rom access user rom access mca04383 255 1 int. ram 0 user rom boot-rom access to int. rom enabled access to external bus disabled 16 mbytes mca04384 255 1 int. ram 0 user rom boot-rom access to int. rom enabled access to external bus enabled 16 mbytes mca04385 255 1 int. ram 0 user rom depends on reset config. depends on reset config. (ea, p0) 16 mbytes
c167cs derivatives the bootstrap loader users manual 15-5 v2.0, 2000-07 15.2 loading the startup code after sending the identification byte the bsl enters a loop to receive 32 bytes via asc0. these bytes are stored sequentially into locations 00fa40 h through 00fa5f h of the internal ram. so up to 16 instructions may be placed into the ram area. to execute the loaded code the bsl then jumps to location 00fa40 h , i.e. the first loaded instruction. the bootstrap loading sequence is now terminated, the c167cs remains in bsl mode, however. most probably the initially loaded routine will load additional code or data, as an average application is likely to require substantially more than 16 instructions. this second receive loop may directly use the pre-initialized interface asc0 to receive data and store it to arbitrary user-defined locations. this second level of loaded code may be the final application code. it may also be another, more sophisticated, loader routine that adds a transmission protocol to enhance the integrity of the loaded code or data. it may also contain a code sequence to change the system configuration and enable the bus interface to store the received data into external memory. this process may go through several iterations or may directly execute the final application. in all cases the c167cs will still run in bsl mode, i.e. with the watchdog timer disabled and limited access to the internal code memory. all code fetches from the internal rom area (000000 h 007fff h or 010000 h 017fff h , if mapped to segment 1) are redirected to the special boot-rom. data fetches access will access the internal code memory of the c167cs, if any is available, but will return undefined data on romless devices. note: data fetches from a protected rom will not be executed. 15.3 exiting bootstrap loader mode in order to execute a program in normal mode (i.e. watchdog timer active, full access to user memory, etc.), the bsl mode must be terminated first. the c167cs exits bsl mode in two ways: upon a software reset, ignoring the external configuration (p0l.4 or rd ) upon a hardware reset, not configuraing bsl mode. after the (non-bsl) reset the c167cs will start executing out of user memory as externally configured via port0 or rd /ale (depending on ea ).
c167cs derivatives the bootstrap loader users manual 15-6 v2.0, 2000-07 15.4 choosing the baudrate for the bsl the calculation of the serial baudrate for asc0 from the length of the first zero byte that is received, allows the operation of the bootstrap loader of the c167cs with a wide range of baudrates. however, the upper and lower limits have to be kept, in order to ensure proper data transfer. the c167cs uses timer t6 to measure the length of the initial zero byte. the quantization uncertainty of this measurement implies the first deviation from the real baudrate, the next deviation is implied by the computation of the s0brl reload value from the timer contents. the formula below shows the association: for a correct data transfer from the host to the c167cs the maximum deviation between the internal initialized baudrate for asc0 and the real baudrate of the host should be below 2.5%. the deviation (f b , in percent) between host baudrate and c167cs baudrate can be calculated via the formula below: note: function (f b ) does not consider the tolerances of oscillators and other devices supporting the serial communication. this baudrate deviation is a nonlinear function depending on the cpu clock and the baudrate of the host. the maxima of the function (f b ) increase with the host baudrate due to the smaller baudrate prescaler factors and the implied higher quantization error (see figure 15-3 ). f cpu 32 s0brl 1 + () --------------------------------------------- - b c167cs = s0brl t6 36 C 72 ------------------- - = t6 9 4 -- - f cpu b host -------------- = , f b b contr b host C b contr ------------------------------------ - 100% = f b 2,5% ,
c167cs derivatives the bootstrap loader users manual 15-7 v2.0, 2000-07 figure 15-3 baudrate deviation between host and c167cs the minimum baudrate (b low in figure 15-3 ) is determined by the maximum count capacity of timer t6, when measuring the zero byte, i.e. it depends on the cpu clock. the minimum baudrate is obtained by using the maximum t6 count 2 16 in the baudrate formula. baudrates below b low would cause t6 to overflow. in this case asc0 cannot be initialized properly and the communication with the external host is likely to fail. the maximum baudrate (b high in figure 15-3 ) is the highest baudrate where the deviation still does not exceed the limit, i.e. all baudrates between b low and b high are below the deviation limit. b high marks the baudrate up to which communication with the external host will work properly without additional tests or investigations. higher baudrates , however, may be used as long as the actual deviation does not exceed the indicated limit. a certain baudrate (marked i) in figure 15-3 ) may e.g. violate the deviation limit, while an even higher baudrate (marked ii) in figure 15-3 ) stays very well below it. any baudrate can be used for the bootstrap loader provided that the following three prerequisites are fulfilled: ? the baudrate is within the specified operating range for the asc0 ? the external host is able to use this baudrate ? the computed deviation error is below the limit. table 15-2 bootstrap loader baudrate ranges f cpu [mhz] 10 12 16 20 25 33 b max 312,500 375,000 500,000 625,000 781,250 1,031,250 b high 9,600 19,200 19,200 19,200 38,400 38,400 b stdmin 600 600 600 1,200 1,200 1,200 b low 344 412 550 687 859 1,133 mca02260 b f 2.5% low b b high i ii b host
c167cs derivatives the bootstrap loader users manual 15-8 v2.0, 2000-07 note: when the bootstrap loader mode is entered via an internal reset (ea = 1), the default configuration selects the prescaler for clock generation. in this case the bootstrap loader will begin to operate with f cpu = f osc / 2 which will limit the maximum baudrate for asc0 at low input frequencies intended for pll operation. higher levels of the bootstrapping sequence can then switch the clock generation mode (via register rstcon) e.g. to pll in order to achieve higher baudrates for the download.
c167cs derivatives the capture/compare units users manual 16-1 v2.0, 2000-07 16 the capture/compare units the c167cs provides two almost identical capture/compare (capcom) units which only differ in the way they are connected to the c167css io pins. they provide 32 channels which interact with 4 timers. the capcom units can capture the contents of a timer on specific internal or external events, or they can compare a timers content with given values and modify output signals in case of a match. with this mechanism they support generation and control of timing sequences on up to 16 channels per unit with a minimum of software intervention. figure 16-1 sfrs and port pins associated with the capcom units e mca04386 dp1h p1h odp2 e dp2 p2 odp3 e dp3 p3 e odp7 dp7 p7 odp8 e dp8 p8 t0 t0rel t1 t1rel t7 e t7rel e t8 e t8rel e cc0-3 cc4-7 cc8-11 cc12-15 cc16-19 cc20-23 cc24-27 cc28-31 t01con t78con ccm0 ccm1 ccm2 ccm3 ccm4 ccm5 ccm6 ccm7 t0ic t1ic t7ic e t8ic e cc0ic-3ic cc4ic-7ic cc8ic-11ic cc12ic-15ic cc16ic-19ic cc20ic-23ic cc24ic-27ic cc28ic-31ic ports & direction control alternate functions data registers control registers interrupt control cc0io/p2.0..cc15io/p2.15 cc16io/p8.0..cc23io/p8.7 cc28io/p7.4..cc31io/p7.7 cc24io/p1h.4..cc27io/ p1h.7 odpx port x open drain control register dpx port x direction control register px port x data register t01con capcom1 timers t0/t1 control register t78con capcom2 timers t7/t8 control register t0ic/t1ic capcom1 timer 0/1 interrupt ctrl. reg. t7ic/t8ic capcom2 timer 7/8 interrupt ctrl. reg. txrel capcom timer x reload register e e e e tx capcom timer x register cc0..15 capcom1 register 0..15 cc16..31 capcom2 register 16..31 ccm0..3 capcom1 mode control register 0..3 ccm4..7 capcom2 mode control register 4..7 cc0..15ic capcom1 interrupt ctrl. reg. 0..15 cc16..31ic capcom2 interrupt ctrl. reg. 16..31
c167cs derivatives the capture/compare units users manual 16-2 v2.0, 2000-07 from the programmers point of view, the term capcom unit refers to a set of sfrs which are associated with this peripheral, including the port pins which may be used for alternate input/output functions including their direction control bits. a capcom unit is typically used to handle high speed io tasks such as pulse and waveform generation, pulse width modulation, or recording of the time at which specific events occur. it also allows the implementation of up to 16 software timers. the maximum resolution of the capcom units is 8 cpu clock cycles (= 16 tcl). each capcom unit consists of two 16-bit timers (t0/t1 in capcom1, t7/t8 in capcom2), each with its own reload register (txrel), and a bank of sixteen dual purpose 16-bit capture/compare registers (cc0 through cc15 in capcom1, cc16 through cc31 in capcom2). the input clock for the capcom timers is programmable to several prescaled values of the cpu clock, or it can be derived from an overflow/underflow of timer t6 in block gpt2. t0 and t7 may also operate in counter mode (from an external input) where they can be clocked by external events. each capture/compare register may be programmed individually for capture or compare function, and each register may be allocated to either timer of the associated unit. all capture/compare registers of each module have one port pin associated with it, respectively, which serves as an input pin for the capture function or as an output pin for the compare function. the capture function causes the current timer contents to be latched into the respective capture/compare register triggered by an event (transition) on its associated port pin. the compare function may cause an output signal transition on that port pin whose associated capture/compare register matches the current timer contents. specific interrupt requests are generated upon each capture/compare event or upon timer overflow. figure 16-2 shows the basic structure of the two capcom units.
c167cs derivatives the capture/compare units users manual 16-3 v2.0, 2000-07 figure 16-2 capcom unit block diagram table 16-1 capcom channel port connections unit channel port capture compare capcom1 cc0io cc15io p2.0 p2.15 input output capcom2 cc16io cc23io p8.0 p8.7 input output cc24io cc27io p1h.4 p1h.7 input output cc28io cc31io p7.4 p7.7 input output s = 32 s = 32 s = 32 s = 32 mcb02143b mode control (capture or compare) 2 n : 1 f cpu tx input control capcom timer tx ty input control txin interrupt request gpt2 timer t6 over/underflow 2 n : 1 f cpu gpt2 timer t6 over/underflow ccxio ccxio 16 capture inputs 16 compare outputs reload reg. txrel capcom timer ty reload reg. tyrel interrupt request 16 capture/compare interrupt request 16-bit capture/ compare registers x = 0, 1 y = 7, 8 n = 3 10
c167cs derivatives the capture/compare units users manual 16-4 v2.0, 2000-07 16.1 the capcom timers the primary use of the timers t0/t1 and t7/t8 is to provide two independent time bases (16 tcl maximum resolution) for the capture/compare registers of each unit, but they may also be used independent of the capture/compare registers. the basic structure of the four timers is identical, while the selection of input signals is different for timers t0/t7 and timers t1/t8 (see figure 16-3 and figure 16-4 ). figure 16-3 block diagram of capcom timers t0 and t7 figure 16-4 block diagram of capcom timers t1 and t8 note: when an external input signal is connected to the input lines of both t0 and t7, these timers count the input signal synchronously. thus the two timers can be regarded as one timer whose contents can be compared with 32 capture registers. mcb02013 capcom timer tx interrupt request 2 n : 1 txl txin txi f cpu mux txr txi txm gpt2 timer t6 over/underflow reload reg. txrel input control edge select x = 0, 7 mcb02014 capcom timer tx interrupt request 2 n : 1 txl f cpu mux txr txm gpt2 timer t6 over/underflow reload reg. txrel x = 1, 8
c167cs derivatives the capture/compare units users manual 16-5 v2.0, 2000-07 the functions of the capcom timers are controlled via the bitaddressable 16-bit control registers t01con and t78con. the high-byte of t01con controls t1, the low-byte of t01con controls t0, the high-byte of t78con controls t8, the low-byte of t78con controls t7. the control options are identical for all four timers (except for external input). t01con capcom timer 0/1 ctrl. reg. sfr (ff50 h /a8 h ) reset value: 0000 h 1514131211109876543210 - t1r - - t1m t1i - t0r - - t0m t0i - rw - - rw rw - rw - - rw rw t78con capcom timer 7/8 ctrl. reg. sfr (ff20 h /90 h ) reset value: 0000 h 1514131211109876543210 - t8r - - t8m t8i - t7r - - t7m t7i - rw - - rw rw - rw - - rw rw bit function txi timer/counter x input selection timer mode (txm = 0): input frequency = f cpu / 2 ( + 3) see also table 16-2 - table 16-4 for examples. counter mode (txm = 1): 000 overflow/underflow of gpt2 timer 6 001 positive (rising) edge on pin t7in 1) 010 negative (falling) edge on pin t7in 1) 011 any edge (rising and falling) on pin t7in 1) 1xx reserved 1) this selection is available for timers t0 and t7. timers t1 and t8 will stop at this selection! txm timer/counter x mode selection 0: timer mode (input derived from internal clock) 1: counter mode (input from external input or t6) txr timer/counter x run control 0: timer/counter x is disabled 1: timer/counter x is enabled
c167cs derivatives the capture/compare units users manual 16-6 v2.0, 2000-07 the timer run flags t0r, t1r, t7r, and t8r allow for enabling and disabling the timers. the following description of the timer modes and operation always applies to the enabled state of the timers, i.e. the respective run flag is assumed to be set to 1. in all modes, the timers are always counting upward. the current timer values are accessible for the cpu in the timer registers tx, which are non-bitaddressable sfrs. when the cpu writes to a register tx in the state immediately before the respective timer increment or reload is to be performed, the cpu write operation has priority and the increment or reload is disabled to guarantee correct timer operation. timer mode the bits txm in sfrs t01con and t78con select between timer or counter mode for the respective timer. in timer mode (txm = 0), the input clock for a timer is derived from the internal cpu clock divided by a programmable prescaler. the different options for the prescaler are selected separately for each timer by the bit fields txi. the input frequencies f tx for tx are determined as a function of the cpu clock as follows, where represents the contents of the bit field txi: when a timer overflows from ffff h to 0000 h it is reloaded with the value stored in its respective reload register txrel. the reload value determines the period p tx between two consecutive overflows of tx as follows: after a timer has been started by setting its run flag (txr) to 1, the first increment will occur within the time interval which is defined by the selected timer resolution. all further increments occur exactly after the time defined by the timer resolution. when both timers of a capcom unit are to be incremented or reloaded at the same time t0 is always serviced one cpu clock before t1, t7 before t8, respectively. the timer input frequencies, resolution and periods which result from the selected prescaler option in txi when using a certain cpu clock are listed in table 16-2 - table 16-4 . the numbers for the timer periods are based on a reload value of 0000 h . note that some numbers may be rounded to 3 significant digits. f tx = f cpu 2 ( + 3) p tx = f cpu (2 16 C ) 2 ( + 3)
c167cs derivatives the capture/compare units users manual 16-7 v2.0, 2000-07 table 16-2 timer input frequencies, resolution and period @ 20 mhz f cpu = 20 mhz timer input selection txi 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler (1:n) 8 16 32 64 128 256 512 1024 input frequency 2.5 mhz 1.25 mhz 625 khz 312.5 khz 156.25 khz 78.125 khz 39.06 khz 19.53 khz resolution 400 ns 800 ns 1.6 m s 3.2 m s 6.4 m s 12.8 m s 25.6 m s 51.2 m s period 26 ms 52.5 ms 105 ms 210 ms 420 ms 840 ms 1.68 s 3.36 s table 16-3 timer input frequencies, resolution and period @ 25 mhz f cpu = 25 mhz timer input selection txi 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler (1:n) 8 16 32 64 128 256 512 1024 input frequency 3.125 mhz 1.563 mhz 781.25 khz 390.63 khz 195.31 khz 97.656 khz 48.828 khz 24.414 khz resolution 320 ns 640 ns 1.28 m s 2.56 m s 5.12 m s 10.24 m s 20.48 m s 40.96 m s period 21 ms 42 ms 84 ms 168 ms 336 ms 672 ms 1.344 s 2.688 s table 16-4 timer input frequencies, resolution and period @ 33 mhz f cpu = 33 mhz timer input selection txi 000 b 001 b 010 b 011 b 100 b 101 b 110 b 111 b prescaler (1:n) 8 16 32 64 128 256 512 1024 input frequency 4.125 mhz 2.063 mhz 1.031 mhz 515.63 khz 257.81 khz 128.91 khz 64.453 khz 32.227 khz resolution 242 ns 485 ns 970 ns 1.94 m s 3.88 m s 7.76 m s 15.52 m s 31.03 m s period 15.89 ms 31.78 ms 63.55 ms 127.10 ms 254.20 ms 508.40 ms 1.017 s 2.034 s
c167cs derivatives the capture/compare units users manual 16-8 v2.0, 2000-07 counter mode the bits txm in sfrs t01con and t78con select between timer or counter mode for the respective timer. in counter mode (txm = 1) the input clock for a timer can be derived from the overflows/underflows of timer t6 in block gpt2. in addition, timers t0 and t7 can be clocked by external events. either a positive, a negative, or both a positive and a negative transition at pin t0in or t7in (alternate port input function), respectively, can be selected to cause an increment of t0/t7. when t1 or t8 is programmed to run in counter mode, bit field txi is used to enable the overflows/underflows of timer t6 as the count source. this is the only option for these timers and it is selected by the combination txi = 000 b . when bit field txi is programmed to any other valid combination, the respective timer will stop. when t0 or t7 is programmed to run in counter mode, bit field txi is used to select the count source and transition (if the source is the input pin) which should cause a count trigger (see description of txycon for the possible selections). note: in order to use pin t0in or t7in as external count input pin, the respective port pin must be configured as input, i.e. the corresponding direction control bit must be cleared (dpx.y = 0). if the respective port pin is configured as output, the associated timer may be clocked by modifying the port output latches px.y via software, e.g. for testing purposes. the maximum external input frequency to t0 or t7 in counter mode is f cpu /16. to ensure that a signal transition is properly recognized at the timer input, an external count input signal should be held for at least 8 cpu clock cycles before it changes its level again. the incremented count value appears in sfr t0/t7 within 8 cpu clock cycles after the signal transition at pin txin. reload a reload of a timer with the 16-bit value stored in its associated reload register in both modes is performed each time a timer would overflow from ffff h to 0000 h . in this case the timer does not wrap around to 0000 h , but rather is reloaded with the contents of the respective reload register txrel. the timer then resumes incrementing starting from the reloaded value. the reload registers txrel are not bitaddressable.
c167cs derivatives the capture/compare units users manual 16-9 v2.0, 2000-07 16.2 capcom unit timer interrupts upon a timer overflow the corresponding timer interrupt request flag txir for the respective timer will be set. this flag can be used to generate an interrupt or trigger a pec service request, when enabled by the respective interrupt enable bit txie. each timer has its own bitaddressable interrupt control register (txic) and its own interrupt vector (txint). the organization of the interrupt control registers txic is identical with the other interrupt control registers. note: please refer to the general interrupt control register description for an explanation of the control fields. t0ic capcom t0 intr. ctrl. reg. sfr (ff9c h /ce h ) reset value: - - 00 h 1514131211109876543210 t0ir t0ie ilvl glvl - - - - - - - - rwh rw rw rw t1ic capcom t1 intr. ctrl. reg. sfr (ff9e h /cf h ) reset value: - - 00 h 1514131211109876543210 t1ir t1ie ilvl glvl - - - - - - - - rwh rw rw rw t7ic capcom t7 intr. ctrl. reg. esfr (f17a h /be h ) reset value: - - 00 h 1514131211109876543210 t7ir t7ie ilvl glvl - - - - - - - - rwh rw rw rw t8ic capcom t8 intr. ctrl. reg. esfr (f17c h /bf h ) reset value: - - 00 h 1514131211109876543210 t8ir t8ie ilvl glvl - - - - - - - - rwh rw rw rw
c167cs derivatives the capture/compare units users manual 16-10 v2.0, 2000-07 16.3 capture/compare registers the 16-bit capture/compare registers cc0 through cc31 are used as data registers for capture or compare operations with respect to timers t0/t1 and t7/t8. the capture/ compare registers are not bitaddressable. the functions of the 32 capture/compare registers are controlled by 8 bitaddressable 16-bit mode control registers named ccm0 ccm7 which are organized identically (see description below). each register contains bits for mode selection and timer allocation of four capture/compare registers. capture/compare mode registers for the capcom1 unit (cc0 cc15) ccm0 capcom mode ctrl. reg. 0 sfr (ff52 h /a9 h ) reset value: 0000 h 1514131211109876543210 acc 3 ccmod3 acc 2 ccmod2 acc 1 ccmod1 acc 0 ccmod0 rw rw rw rw rw rw rw rw ccm1 capcom mode ctrl. reg. 1 sfr (ff54 h /aa h ) reset value: 0000 h 1514131211109876543210 acc 7 ccmod7 acc 6 ccmod6 acc 5 ccmod5 acc 4 ccmod4 rw rw rw rw rw rw rw rw ccm2 capcom mode ctrl. reg. 2 sfr (ff56 h /ab h ) reset value: 0000 h 1514131211109876543210 acc 11 ccmod11 acc 10 ccmod10 acc 9 ccmod9 acc 8 ccmod8 rw rw rw rw rw rw rw rw ccm3 capcom mode ctrl. reg. 3 sfr (ff58 h /ac h ) reset value: 0000 h 1514131211109876543210 acc 15 ccmod15 acc 14 ccmod14 acc 13 ccmod13 acc 12 ccmod12 rw rw rw rw rw rw rw rw
c167cs derivatives the capture/compare units users manual 16-11 v2.0, 2000-07 capture/compare mode registers for the capcom2 unit (cc16 cc32 ) ccm4 capcom mode ctrl. reg. 4 sfr (ff22 h /91 h ) reset value: 0000 h 1514131211109876543210 acc 19 ccmod19 acc 18 ccmod18 acc 17 ccmod17 acc 16 ccmod16 rw rw rw rw rw rw rw rw ccm5 capcom mode ctrl. reg. 5 sfr (ff24 h /92 h ) reset value: 0000 h 1514131211109876543210 acc 23 ccmod23 acc 22 ccmod22 acc 21 ccmod21 acc 20 ccmod20 rw rw rw rw rw rw rw rw ccm6 capcom mode ctrl. reg. 6 sfr (ff26 h /93 h ) reset value: 0000 h 1514131211109876543210 acc 27 ccmod27 acc 26 ccmod26 acc 25 ccmod25 acc 24 ccmod24 rw rw rw rw rw rw rw rw ccm7 capcom mode ctrl. reg. 7 sfr (ff28 h /94 h ) reset value: 0000 h 1514131211109876543210 acc 31 ccmod31 acc 30 ccmod30 acc 29 ccmod29 acc 28 ccmod28 rw rw rw rw rw rw rw rw bit function ccmodx mode selection for capture/compare register ccx the available capture/compare modes are listed in table 16-5 . accx allocation bit for capture/compare register ccx 0: ccx allocated to timer t7 1: ccx allocated to timer t8
c167cs derivatives the capture/compare units users manual 16-12 v2.0, 2000-07 each of the registers ccx may be individually programmed for capture mode or one of 4 different compare modes, and may be allocated individually to one of the two timers of the respective capcom unit (t0 or t1, and t7 or t8, respectively). a special combination of compare modes additionally allows the implementation of a double- register compare mode. when capture or compare operation is disabled for one of the ccx registers, it may be used for general purpose variable storage. the detailed discussion of the capture and compare modes is valid for all the capture/ compare channels, so registers, bits and pins are only referenced by the placeholder x. note: a capture or compare event on channel 31 may be used to trigger a channel injection on the c167css a/d converter if enabled. table 16-5 selection of capture modes and compare modes ccmodx selected operating mode 0 0 0 disable capture and compare modes the respective capcom register may be used for general variable storage. 0 0 1 capture on positive transition (rising edge) at pin ccxio 0 1 0 capture on negative transition (falling edge) at pin ccxio 0 1 1 capture on positive and negative transition (both edges) at pin ccxio 1 0 0 compare mode 0: interrupt only several interrupts per timer period; enables double-register compare mode for registers cc8 cc15 and cc24 cc31. 1 0 1 compare mode 1: toggle output pin on each match several compare events per timer period; this mode is required for double- register compare mode for registers cc0 cc7 and cc16 cc23. 1 1 0 compare mode 2: interrupt only only one interrupt per timer period. 1 1 1 compare mode 3: set output pin on each match reset output pin on each timer overflow; only one interrupt per timer period.
c167cs derivatives the capture/compare units users manual 16-13 v2.0, 2000-07 16.4 capture mode in response to an external event the content of the associated timer (t0/t1 or t7/t8, depending on the used capcom unit and the state of the allocation control bit accx) is latched into the respective capture register ccx. the external event causing a capture can be programmed to be either a positive, a negative, or both a positive or a negative transition at the respective external input pin ccxio. the triggering transition is selected by the mode bits ccmodx in the respective capcom mode control register. in any case, the event causing a capture will also set the respective interrupt request flag ccxir, which can cause an interrupt or a pec service request, when enabled. figure 16-5 capture mode block diagram in order to use the respective port pin as external capture input pin ccxio for capture register ccx, this port pin must be configured as input, i.e. the corresponding direction control bit must be set to 0. to ensure that a signal transition is properly recognized, an external capture input signal should be held for at least 8 cpu clock cycles before it changes its level. during these 8 cpu clock cycles the capture input signals are scanned sequentially. when a timer is modified or incremented during this process, the new timer contents will already be captured for the remaining capture registers within the current scanning sequence. note: when the timer modification can generate an overflow the capture interrupt routine should check if the timer overflow was serviced during these 8 cpu clock cycles. if pin ccxio is configured as output, the capture function may be triggered by modifying the corresponding port output latch via software, e.g. for testing purposes. edge select mcb02015 capture reg. ccx capcom timer ty interrupt request ccxio input clock ccmodx interrupt request x = 31...0 y = 0, 1, 7, 8
c167cs derivatives the capture/compare units users manual 16-14 v2.0, 2000-07 16.5 compare modes the compare modes allow triggering of events (interrupts and/or output signal transitions) with minimum software overhead. in all compare modes, the 16-bit value stored in compare register ccx (in the following also referred to as compare value) is continuously compared with the contents of the allocated timer (t0/t1 or t7/t8). if the current timer contents match the compare value, an appropriate output signal, which is based on the selected compare mode, can be generated at the corresponding output pin ccxio and the associated interrupt request flag ccxir is set, which can generate an interrupt request (if enabled). as for capture mode, the compare registers are also processed sequentially during compare mode. when two or more compare registers are programmed to the same compare value, their corresponding interrupt request flags will be set to 1 and the selected output signals will be generated within 8 cpu clock cycles after the allocated timer is incremented to this compare value. further compare events on the same compare value are disabled 1) until the timer is incremented again or written to by software. after a reset, compare events for register ccx will only become enabled, if the allocated timer has been incremented or written to by software and one of the compare modes described in the following has been selected for this register. the different compare modes which can be programmed for a given compare register ccx are selected by the mode control field ccmodx in the associated capture/compare mode control register. in the following, each of the compare modes, including the special double-register mode, is discussed in detail. compare mode 0 this is an interrupt-only mode which can be used for software timing purposes. compare mode 0 is selected for a given compare register ccx by setting bit field ccmodx of the corresponding mode control register to 100 b . in this mode, the interrupt request flag ccxir is set each time a match is detected between the content of compare register ccx and the allocated timer. several of these compare events are possible within a single timer period, when the compare value in register ccx is updated during the timer period. the corresponding port pin ccxio is not affected by compare events in this mode and can be used as general purpose io pin. if compare mode 0 is programmed for one of the registers cc8 cc15 or cc24 cc31, the double-register compare mode becomes enabled for this register if the corresponding bank 1 register is programmed to compare mode 1 (see double- register compare mode on page 16-19 ). 1) compare events are detected sequentially, where a sequence (checking 8 times 2 channels each) takes 8 cpu clock cycles. even if more sequences are executed before the timer increments (lower timer frequency) a given compare value only results in one single compare event.
c167cs derivatives the capture/compare units users manual 16-15 v2.0, 2000-07 figure 16-6 compare mode 0 and 1 block diagram note: the port latch and pin remain unaffected in compare mode 0. in the example below, the compare value in register ccx is modified from cv1 to cv2 after compare events #1 and #3, and from cv2 to cv1 after events #2 and #4, etc. this results in periodic interrupt requests from timer ty, and in interrupt requests from register ccx which occur at the time specified by the user through cv1 and cv2. figure 16-7 timing example for compare modes 0 and 1 mcb02016 compare reg. ccx comparator capcom timer ty ccmodx port latch toggle (mode 1) ccxio interrupt request interrupt request input clock x = 31...0 y = 0, 1, 7, 8 not for cc27...cc24 mcb02017 contents of ty tyir ccxir ccxir tyir ccxir ccxir tyir interrupt requests: t event #1 ccx: = cv2 event #2 ccx: = cv1 event #3 ccx: = cv2 event #4 ccx: = cv1 x = 31...0 y = 0, 1, 7, 8 output pin ccxio only effected in mode 1. no changes in mode 0. 0000 h reload value compare value cv1 compare value cv2 ffff h
c167cs derivatives the capture/compare units users manual 16-16 v2.0, 2000-07 compare mode 1 compare mode 1 is selected for register ccx by setting bit field ccmodx of the corresponding mode control register to 101 b . when a match between the content of the allocated timer and the compare value in register ccx is detected in this mode, interrupt request flag ccxir is set to 1, and in addition the corresponding output pin ccxio (alternate port output function) is toggled. for this purpose, the state of the respective port output latch (not the pin) is read, inverted, and then written back to the output latch. compare mode 1 allows several compare events within a single timer period. an overflow of the allocated timer has no effect on the output pin, nor does it disable or enable further compare events. in order to use the respective port pin as compare signal output pin ccxio for compare register ccx in compare mode 1, this port pin must be configured as output, i.e. the corresponding direction control bit must be set to 1. with this configuration, the initial state of the output signal can be programmed or its state can be modified at any time by writing to the port output latch. in compare mode 1 the port latch is toggled upon each compare event (see figure 16-7 ). if compare mode 1 is programmed for one of the registers cc0 cc7 or cc16 cc23 the double-register compare mode becomes enabled for this register if the corresponding bank 2 register is programmed to compare mode 0 (see double- register compare mode on page 16-19 ). note: if the port output latch is written to by software at the same time it would be altered by a compare event, the software write will have priority. in this case the hardware- triggered change will not become effective. compare mode 2 compare mode 2 is an interrupt-only mode similar to compare mode 0, but only one interrupt request per timer period will be generated. compare mode 2 is selected for register ccx by setting bit field ccmodx of the corresponding mode control register to 110 b . when a match is detected in compare mode 2 for the first time within a timer period, the interrupt request flag ccxir is set to 1. the corresponding port pin is not affected and can be used for general purpose io. however, after the first match has been detected in this mode, all further compare events within the same timer period are disabled for compare register ccx until the allocated timer overflows. this means, that after the first match, even when the compare register is reloaded with a value higher than the current timer value, no compare event will occur until the next timer period.
c167cs derivatives the capture/compare units users manual 16-17 v2.0, 2000-07 in the example below, the compare value in register ccx is modified from cv1 to cv2 after compare event #1. compare event #2, however, will not occur until the next period of timer ty. figure 16-8 compare mode 2 and 3 block diagram note: the port latch and pin remain unaffected in compare mode 2. figure 16-9 timing example for compare modes 2 and 3 mcb02019 compare reg. ccx comparator capcom timer ty ccmodx port latch (mode 3) ccxio interrupt request interrupt request input clock set reset not for cc27...cc24 x = 31...0 y = 0, 1, 7, 8 mcb02021 0000 h ffff h contents of ty tyir ccxir tyir ccxir tyir interrupt requests: time event #1 ccx: = cv2 event #2 ccx: = cv1 0 1 state ccxio: x = 31...0 y = 0, 1, 7, 8 output pin ccxio only effected in mode 3. no changes in mode 2. reload value compare value cv1 compare value cv2
c167cs derivatives the capture/compare units users manual 16-18 v2.0, 2000-07 compare mode 3 compare mode 3 is selected for register ccx by setting bit field ccmodx of the corresponding mode control register to 111 b . in compare mode 3 only one compare event will be generated per timer period. when the first match within the timer period is detected the interrupt request flag ccxir is set to 1 and also the output pin ccxio (alternate port function) will be set to 1. the pin will be reset to 0, when the allocated timer overflows. if a match was found for register ccx in this mode, all further compare events during the current timer period are disabled for ccx until the corresponding timer overflows. if, after a match was detected, the compare register is reloaded with a new value, this value will not become effective until the next timer period. in order to use the respective port pin as compare signal output pin ccxio for compare register ccx in compare mode 3 this port pin must be configured as output, i.e. the corresponding direction control bit must be set to 1. with this configuration, the initial state of the output signal can be programmed or its state can be modified at any time by writing to the port output latch. in compare mode 3 the port latch is set upon a compare event and cleared upon a timer overflow (see figure 16-9 ). however, when compare value and reload value for a channel are equal the respective interrupt requests will be generated, only the output signal is not changed (set and clear would coincide in this case). note: if the port output latch is written to by software at the same time it would be altered by a compare event, the software write will have priority. in this case the hardware- triggered change will not become effective.
c167cs derivatives the capture/compare units users manual 16-19 v2.0, 2000-07 double-register compare mode in double-register compare mode two compare registers work together to control one output pin. this mode is selected by a special combination of modes for these two registers. for double-register mode the 16 capture/compare registers of each capcom unit are regarded as two banks of 8 registers each. registers cc0 cc7 and cc16 cc23 form bank 1 while registers cc8 cc15 and cc24 cc31 form bank 2 (respectively). for double-register mode a bank 1 register and a bank 2 register form a register pair. both registers of this register pair operate on the pin associated with the bank 1 register (pins cc0io cc7io and cc16io cc23io). the relationship between the bank 1 and bank 2 register of a pair and the effected output pins for double-register compare mode is listed in table 16-6 . the double-register compare mode can be programmed individually for each register pair. in order to enable double-register mode the respective bank 1 register (see table 16-6 ) must be programmed to compare mode 1 and the corresponding bank 2 register (see table 16-6 ) must be programmed to compare mode 0. if the respective bank 1 compare register is disabled or programmed for a mode other than mode 1 the corresponding bank 2 register will operate in compare mode 0 (interrupt-only mode). in the following, a bank 2 register (programmed to compare mode 0) will be referred to as ccz while the corresponding bank 1 register (programmed to compare mode 1) will be referred to as ccx. table 16-6 register pairs for double-register compare mode capcom1 unit capcom2 unit register pair associated output pin register pair associated output pin bank 1 bank 2 bank 1 bank 2 cc0 cc8 cc0io cc16 cc24 cc16io cc1 cc9 cc1io cc17 cc25 cc17io cc2 cc10 cc2io cc18 cc26 cc18io cc3 cc11 cc3io cc19 cc27 cc19io cc4 cc12 cc4io cc20 cc28 cc20io cc5 cc13 cc5io cc21 cc29 cc21io cc6 cc14 cc6io cc22 cc30 cc22io cc7 cc15 cc7io cc23 cc31 cc23io
c167cs derivatives the capture/compare units users manual 16-20 v2.0, 2000-07 when a match is detected for one of the two registers in a register pair (ccx or ccz) the associated interrupt request flag (ccxir or cczir) is set to 1 and pin ccxio corresponding to bank 1 register ccx is toggled. the generated interrupt always corresponds to the register that caused the match. note: if a match occurs simultaneously for both register ccx and register ccz of the register pair pin ccxio will be toggled only once but two separate compare interrupt requests will be generated, one for vector ccxint and one for vector cczint. in order to use the respective port pin as compare signal output pin ccxio for compare register ccx in double-register compare mode, this port pin must be configured as output, i.e. the corresponding direction control bit must be set to 1. with this configuration, the output pin has the same characteristics as in compare mode 1. figure 16-10 double-register compare mode block diagram mcb02022 comparator capcom timer ty mode 0 (ccmodz) port latch toggle ccxio interrupt request input clock compare reg. ccz comparator compare reg. ccx mode 1 (ccmodx) 1 interrupt request x = 23...16, 7...0 y = 0, 1, 7, 8 z = 31...24, 15...8
c167cs derivatives the capture/compare units users manual 16-21 v2.0, 2000-07 in this configuration example, the same timer allocation was chosen for both compare registers, but each register may also be individually allocated to one of the two timers of the respective capcom unit. in the timing example for this compare mode (below) the compare values in registers ccx and ccz are not modified. note: the pins cczio (which do not serve for double-register compare mode) may be used for general purpose io. figure 16-11 timing example for double-register compare mode mcb02023 0000 h ffff h contents of ty tyir ccxir tyir ccxir tyir interrupt requests: time 0 1 state of ccxio: ccxir ccxir x = 23...16, 7...0 y = 0, 1, 7, 8 z = 31...24, 15...8 reload value compare value ccx compare value ccz
c167cs derivatives the capture/compare units users manual 16-22 v2.0, 2000-07 16.6 capture/compare interrupts upon a capture or compare event, the interrupt request flag ccxir for the respective capture/compare register ccx is set to 1. this flag can be used to generate an interrupt or trigger a pec service request when enabled by the interrupt enable bit ccxie. capture interrupts can be regarded as external interrupt requests with the additional feature of recording the time at which the triggering event occurred (see also section 5.8 ). each of the 32 capture/compare registers has its own bitaddressable interrupt control register (cc0ic cc31ic) and its own interrupt vector (cc0int cc31int). these registers are organized the same way as all other interrupt control registers. the basic register layout is shown below, table 16-7 lists the associated addresses. note: please refer to the general interrupt control register description for an explanation of the control fields. ccxic capcom intr. ctrl. reg. (e)sfr ( see table 16-7 ) reset value: - - 00 h 1514131211109876543210 ccx ir ccx ie ilvl glvl - - - - - - - - rwh rw rw rw
c167cs derivatives the capture/compare units users manual 16-23 v2.0, 2000-07 table 16-7 capcom unit interrupt control register addresses capcom1 unit capcom2 unit register address reg. space register address reg. space cc0ic ff78 h /bc h sfr cc16ic f160 h /b0 h esfr cc1ic ff7a h /bd h sfr cc17ic f162 h /b1 h esfr cc2ic ff7c h /be h sfr cc18ic f164 h /b2 h esfr cc3ic ff7e h /bf h sfr cc19ic f166 h /b3 h esfr cc4ic ff80 h /c0 h sfr cc20ic f168 h /b4 h esfr cc5ic ff82 h /c1 h sfr cc21ic f16a h /b5 h esfr cc6ic ff84 h /c2 h sfr cc22ic f16c h /b6 h esfr cc7ic ff86 h /c3 h sfr cc23ic f16e h /b7 h esfr cc8ic ff88 h /c4 h sfr cc24ic f170 h /b8 h esfr cc9ic ff8a h /c5 h sfr cc25ic f172 h /b9 h esfr cc10ic ff8c h /c6 h sfr cc26ic f174 h /ba h esfr cc11ic ff8e h /c7 h sfr cc27ic f176 h /bb h esfr cc12ic ff90 h /c8 h sfr cc28ic f178 h /bc h esfr cc13ic ff92 h /c9 h sfr cc29ic f184 h /c2 h esfr cc14ic ff94 h /ca h sfr cc30ic f18c h /c6 h esfr cc15ic ff96 h /cb h sfr cc31ic f194 h /ca h esfr
c167cs derivatives the pulse width modulation module users manual 17-1 v2.0, 2000-07 17 the pulse width modulation module the pulse width modulation (pwm) module of the c167cs allows the generation of up to 4 independent pwm signals. these pwm signals can be generated within a wide range of output frequencies, which depends on: ? the cpu clock frequency f cpu ? the selected counter resolution ( f cpu / 1 or f cpu / 64) ? the operating mode (edge/center aligned) ? the required pwm resolution (1-bit 16-bit) the maximum pwm output frequency in a real application is primarily determined by the pwm resolution which is required for that application. figure 17-1 sfrs and port pins associated with the pwm module the pulse width modulation module consists of 4 independent pwm channels. each channel has a 16-bit up/down counter ptx, a 16-bit period register ppx with a shadow latch, a 16-bit pulse width register pwx with a shadow latch, two comparators, and the necessary control logic. the operation of all four channels is controlled by two common control registers, pwmcon0 and pwmcon1, and the interrupt control and status is handled by one interrupt control register pwmic, which is also common for all channels. e mca04387 odp7 dp7 p7 pp0 pw0 pp1 pw1 pp2 e pw2 pp3 e pw3 pt0 pt1 pwmcon0 pwmic ports & direction control alternate functions data registers control registers control registers and interrupt control odp7 port 7 open drain control register dp7 port 7 direction control register p7 port 7 data register pwmic pwm interrupt control register ppx pwm period register x pwx pwm pulse width register x ptx pwm counter register x pwmconx pwm control register 0/1 pwmcon1 pt2 pt3 pout0/p7.0 pout1/p7.1 pout2/p7.2 pout3/p7.3 e e e e e e e
c167cs derivatives the pulse width modulation module users manual 17-2 v2.0, 2000-07 figure 17-2 pwm channel block diagram 17.1 operating modes the pwm module provides four different operating modes: ? standard pwm generation (edge aligned pwm) available on all four channels ? symmetrical pwm generation (center aligned pwm) available on all four channels ? burst mode combines channels 0 and 1 ? single shot mode available on channels 2 and 3 note: the output signals of the pwm module are xored with the outputs of the respective port output latches. after reset these latches are cleared, so the pwm signals are directly driven to the port pins. by setting the respective port output latch to 1 the pwm signal may be inverted (xored with 1) before being driven to the port pin. the descriptions below refer to the standard case after reset, i.e. direct driving. write control output control up/down/ clear control write control match match poutx input control user read- & writeable ppx period register shadow register comparator ptx 16-bit up/down counter comparator shadow register pwx pulse width reg. f cpu run enable mcb01948
c167cs derivatives the pulse width modulation module users manual 17-3 v2.0, 2000-07 mode 0: standard pwm generation (edge aligned pwm) mode 0 is selected by clearing the respective bit pmx in register pwmcon1 to 0. in this mode the timer ptx of the respective pwm channel is always counting up until it reaches the value in the associated period shadow register. upon the next count pulse the timer is reset to 0000 h and continues counting up with subsequent count pulses. the pwm output signal is switched to high level when the timer contents are equal to or greater than the contents of the pulse width shadow register. the signal is switched back to low level when the respective timer is reset to 0000 h , i.e. below the pulse width shadow register. the period of the resulting pwm signal is determined by the value of the respective ppx shadow register plus 1, counted in units of the timer resolution. pwm_period mode0 = [ppx] + 1 the duty cycle of the pwm output signal is controlled by the value in the respective pulse width shadow register. this mechanism allows the selection of duty cycles from 0% to 100% including the boundaries. for a value of 0000 h the output will remain at a high level, representing a duty cycle of 100%. for a value higher than the value in the period register the output will remain at a low level, which corresponds to a duty cycle of 0%. figure 17-3 illustrates the operation and output waveforms of a pwm channel in mode 0 for different values in the pulse width register. this mode is referred to as edge aligned pwm, because the value in the pulse width (shadow) register only effects the positive edge of the output signal. the negative edge is always fixed and related to the clearing of the timer.
c167cs derivatives the pulse width modulation module users manual 17-4 v2.0, 2000-07 figure 17-3 operation and output waveform in mode 0 mca01949 ppx period = 7 ptx count value 6 7 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 pwx pulse width = 0 pwx = 1 pwx = 2 pwx = 4 pwx = 6 pwx = 7 pwx = 8 lsr latch shadow register; interrupt request lsr lsr duty cycle 100% 87.5% 75% 50% 25% 12.5% 0%
c167cs derivatives the pulse width modulation module users manual 17-5 v2.0, 2000-07 mode 1: symmetrical pwm generation (center aligned pwm) mode 1 is selected by setting the respective bit pmx in register pwmcon1 to 1. in this mode the timer ptx of the respective pwm channel is counting up until it reaches the value in the associated period shadow register. upon the next count pulse the count direction is reversed and the timer starts counting down now with subsequent count pulses until it reaches the value 0000 h . upon the next count pulse the count direction is reversed again and the count cycle is repeated with the following count pulses. the pwm output signal is switched to a high level when the timer contents are equal to or greater than the contents of the pulse width shadow register while the timer is counting up. the signal is switched back to a low level when the respective timer has counted down to a value below the contents of the pulse width shadow register. so in mode 1 this pwm value controls both edges of the output signal. note that in mode 1 the period of the pwm signal is twice the period of the timer: pwm_period mode1 = 2 ([ppx] + 1) figure 17-4 illustrates the operation and output waveforms of a pwm channel in mode 1 for different values in the pulse width register. this mode is referred to as center aligned pwm, because the value in the pulse width (shadow) register effects both edges of the output signal symmetrically.
c167cs derivatives the pulse width modulation module users manual 17-6 v2.0, 2000-07 figure 17-4 operation and output waveform in mode 1 mca01950 ppx period = 7 ptx count value 0 1 2 3 4 5 6 7 0 1 2 3 4 5 6 7 0 1 pwx pulse width = 0 pwx = 1 pwx = 2 pwx = 4 pwx = 6 pwx = 7 pwx = 8 lsr latch shadow register; interrupt request change count direction lsr duty cycle 100% 87.5% 75% 50% 25% 12.5% 0% 0 1
c167cs derivatives the pulse width modulation module users manual 17-7 v2.0, 2000-07 burst mode burst mode is selected by setting bit pb01 in register pwmcon1 to 1. this mode combines the signals from pwm channels 0 and 1 onto the port pin of channel 0. the output of channel 0 is replaced with the logical and of channels 0 and 1. the output of channel 1 can still be used at its associated output pin (if enabled). each of the two channels can either operate in mode 0 or 1. note: it is guaranteed by design, that no spurious spikes will occur at the output pin of channel 0 in this mode. the output of the and gate will be transferred to the output pin synchronously to internal clocks. xoring of the pwm signal and the port output latch value is done after the anding of channel 0 and 1. figure 17-5 operation and output waveform in burst mode mca01951 pp0 period value pt0 count value channel 0 pp1 pt1 count channel 1 resulting output pout0
c167cs derivatives the pulse width modulation module users manual 17-8 v2.0, 2000-07 single shot mode single shot mode is selected by setting the respective bit psx in register pwmcon1 to 1. this mode is available for pwm channels 2 and 3. in this mode the timer ptx of the respective pwm channel is started via software and is counting up until it reaches the value in the associated period shadow register. upon the next count pulse the timer is cleared to 0000 h and stopped via hardware, i.e. the respective ptrx bit is cleared. the pwm output signal is switched to high level when the timer contents are equal to or greater than the contents of the pulse width shadow register. the signal is switched back to low level when the respective timer is cleared, i.e. is below the pulse width shadow register. thus starting a pwm timer in single shot mode produces one single pulse on the respective port pin, provided that the pulse width value is between 0000 h and the period value. in order to generate a further pulse, the timer has to be started again via software by setting bit ptrx. after starting the timer (i.e. ptrx = 1) the output pulse may be modified via software. writing to timer ptx changes the positive and/or negative edge of the output signal, depending on whether the pulse has already started (i.e. the output is high) or not (i.e. the output is still low). this (multiple) retriggering is always possible while the timer is running, i.e. after the pulse has started and before the timer is stopped. loading counter ptx directly with the value in the respective ppx shadow register will abort the current pwm pulse upon the next clock pulse (counter is cleared and stopped by hardware). by setting the period (ppx), the timer start value (ptx) and the pulse width value (pwx) appropriately, the pulse width (tw) and the optional pulse delay (td) may be varied in a wide range.
c167cs derivatives the pulse width modulation module users manual 17-9 v2.0, 2000-07 figure 17-6 operation and output waveform in single shot mode mca01952 ppx period = 7 ptx count value 0 1 2 3 4 5 6 7 pwx pulse width = 4 lsr; ptrx reset by hardware ptx stopped lsr 1 2 3 4 5 6 7 set ptrx by software set ptrx by software for next pulse ppx period = 7 ptx count value 0 1 2 3 4 5 6 pwx pulse width = 4 trigger before pulse has started: write pwx value to ptx; shortens delay time t d 4 5 6 7 retrigger after pulse has started: write pwx value to ptx 4 5 6 7 0 1 t d t d
c167cs derivatives the pulse width modulation module users manual 17-10 v2.0, 2000-07 17.2 pwm module registers the pwm module is controlled via two sets of registers. the waveforms are selected by the channel specific registers ptx (timer), ppx (period) and pwx (pulse width). three common registers control the operating modes and the general functions (pwmcon0 and pwmcon1) of the pwm module as well as the interrupt behavior (pwmic). up/down counters ptx each counter ptx of a pwm channel is clocked either directly with f cpu or with f cpu /64. bit ptix in register pwmcon0 selects the respective clock source. a pwm counter counts up or down (controlled by hardware), while its respective run control bit ptrx is set. a timer is started (ptrx = 1) via software and is stopped (ptrx = 0) either via hardware or software, depending on its operating mode. control bit ptrx enables or disables the clock input of counter ptx rather than controlling the pwm output signal. note: for the register locations please refer to table 17-2 further below. table 17-1 summarizes the pwm frequencies that result from various combinations of operating mode, counter resolution (input clock) and pulse width resolution. table 17-1 pwm output frequency and resolution inp.clk. ( f cpu /x) (counter resol.) pwm mode 8-bit pwm resolution 10-bit pwm resolution 12-bit pwm resolution 14-bit pwm resolution 16-bit pwm resolution 16 mhz/1 (62.5 ns) 0 1 62.50 khz 31.25 khz 15.63 khz 7.81 khz 3.91 khz 1.95 khz 976.6 hz 488.3 hz 244.1 hz 122.1 hz 16 mhz/64 (4.0 m s) 0 1 976.6 hz 488.3 hz 244.1 hz 122.1 hz 61.04 hz 30.52 hz 15.29 hz 7.63 hz 3.81 hz 1.91 hz 20 mhz/1 (50 ns) 0 1 78.13 khz 39.06 khz 19.53 khz 9.77 khz 4.88 khz 2.44 khz 1.22 khz 610.4 hz 305.2 hz 152.6 hz 20 mhz/64 (3.2 m s) 0 1 1.22 khz 610.4 hz 305.2 hz 152.6 hz 76.29 hz 38.15 hz 19.07 hz 9.54 hz 4.77 hz 2.38 hz 25 mhz/1 (40 ns) 0 1 97.66 khz 48.83 khz 24.41 khz 12.21 khz 6.10 khz 3.05 khz 1.53 khz 762.9 hz 381.5 hz 190.7 hz 25 mhz/64 (2.56 m s) 0 1 1.53 khz 762.9 hz 381.5 hz 190.7 hz 95.37 hz 47.68 hz 23.84 hz 11.92 hz 5.96 hz 2.98 hz 33 mhz/1 (30.3 ns) 0 1 128.9 khz 64.45 khz 32.23 khz 16.11 khz 8.06 khz 4.03 khz 2.01 khz 1.01 khz 503.5 hz 251.8 hz 33 mhz/64 (1.94 m s) 0 1 2.01 khz 1.01 khz 503.5 hz 251.8 hz 125.9 hz 62.94 hz 31.47 hz 15.74 hz 7.87 hz 3.93 hz
c167cs derivatives the pulse width modulation module users manual 17-11 v2.0, 2000-07 period registers ppx the 16-bit period register ppx (see table 17-2 for locations) of a pwm channel determines the period of a pwm cycle, i.e. the frequency of the pwm signal. this register is buffered with a shadow register. the shadow register is loaded from the respective ppx register at the beginning of every new pwm cycle, or upon a write access to ppx, while the timer is stopped. the cpu accesses the ppx register while the hardware compares the contents of the shadow register with the contents of the associated counter ptx. when a match is found between counter and ppx shadow register, the counter is either reset to 0000 h , or the count direction is switched from counting up to counting down, depending on the selected operating mode of that pwm channel. pulse width registers pwx the 16-bit pulse width register pwx (see table 17-2 for locations) of a pwm channel holds the actual pwm pulse width value which corresponds to the duty cycle of the pwm signal. this register is buffered with a shadow register. the cpu accesses the pwx register while the hardware compares the contents of the shadow register with the contents of the associated counter ptx. the shadow register is loaded from the respective pwx register at the beginning of every new pwm cycle, or upon a write access to pwx, while the timer is stopped. when the counter value is greater than or equal to the shadow register value, the pwm signal is set, otherwise it is reset. the output of the comparators may be described by the boolean formula: pwm output signal = [ptx] 3 [pwx shadow latch]. this type of comparison allows a flexible control of the pwm signal. table 17-2 pwm module channel specific register addresses register address register space register address register space pw0 fe30 h /18 h sfr pt0 f030 h /18 h esfr pw1 fe32 h /19 h sfr pt1 f032 h /19 h esfr pw2 fe34 h /1a h sfr pt2 f034 h /1a h esfr pw3 fe36 h /1b h sfr pt3 f036 h /1b h esfr note: these registers are not bitaddressable. pp0 f038 h /1c h esfr pp1 f03a h /1d h esfr pp2 f03c h /1e h esfr pp3 f03e h /1f h esfr
c167cs derivatives the pulse width modulation module users manual 17-12 v2.0, 2000-07 pwm control register pwmcon0 register pwmcon0 controls the function of the timers of the four pwm channels and the channel specific interrupts. having the control bits organized in functional groups allows e.g. to start or stop all 4 pwm timers simultaneously with one bitfield instruction. pwmcon0 pwm control register 0 sfr (ff30 h /98 h ) reset value: 0000 h 1514131211109876543210 pir 3 pir 2 pir 1 pir 0 pie 3 pie 2 pie 1 pie 0 pti 3 pti 2 pti 1 pti 0 ptr 3 ptr 2 ptr 1 ptr 0 rwh rwh rwh rwh rw rw rw rw rw rw rw rw rwh rwh rw rw bit function ptrx pwm timer x run control bit 0: timer ptx is disconnected from its input clock 1: timer ptx is running ptix pwm timer x input clock selection 0: timer ptx clocked with clk cpu 1: timer ptx clocked with clk cpu /64 piex pwm channel x interrupt enable flag 0: interrupt from channel x disabled 1: interrupt from channel x enabled pirx pwm channel x interrupt request flag 0: no interrupt request from channel x 1: channel x interrupt pending (must be reset via software)
c167cs derivatives the pulse width modulation module users manual 17-13 v2.0, 2000-07 pwm control register pwmcon1 register pwmcon1 controls the operating modes and the outputs of the four pwm channels. the basic operating mode for each channel (standard = edge aligned, or symmetrical = center aligned pwm mode) is selected by the mode bits pmx. burst mode (channels 0 and 1) and single shot mode (channel 2 or 3) are selected by separate control bits. the output signal of each pwm channel is individually enabled by bit penx. if the output is not enabled the respective pin can be used for general purpose io and the pwm channel can only be used to generate an interrupt request. pwmcon1 pwm control register 1 sfr (ff32 h /99 h ) reset value: 0000 h 1514131211109876543210 ps3 ps2 - pb 01 ----pm3pm2pm1pm0 pen 3 pen 2 pen 1 pen 0 rw rw - rw - - - - rw rw rw rw rw rw rw rw bit function penx pwm channel x output enable bit 0: channel x output signal disabled, generate interrupt only 1: channel x output signal enabled pmx pwm channel x mode control bit 0: channel x operates in mode 0, i.e. edge aligned pwm 1: channel x operates in mode 1, i.e. center aligned pwm pb01 pwm channel 0/1 burst mode control bit 0: channel 0 and channel 1 work independently in their respective standard mode 1: outputs of channels 0 and 1 are anded to pout0 in burst mode psx pwm channel x single shot mode control bit 0: channel x works in respective standard mode 1: channel x operates in single shot mode
c167cs derivatives the pulse width modulation module users manual 17-14 v2.0, 2000-07 17.3 interrupt request generation each of the four channels of the pwm module can generate an individual interrupt request. each of these channel interrupts can activate the common module interrupt, which actually interrupts the cpu. this common module interrupt is controlled by the pwm module interrupt control register pwmic. the interrupt service routine can determine the active channel interrupt(s) from the channel specific interrupt request flags pirx in register pwmcon0. the interrupt request flag pirx of a channel is set at the beginning of a new pwm cycle, i.e. upon latching the shadow registers (lsr). this indicates that registers ppx and pwx are now ready to receive a new value. if a channel interrupt is enabled via its respective piex bit, also the common interrupt request flag pwmir in register pwmic is set, provided that it is enabled via the common interrupt enable bit pwmie. note: the channel interrupt request flags (pirx in register pwmcon0) are not automatically cleared by hardware upon entry into the interrupt service routine, so they must be cleared via software. the module interrupt request flag pwmir is cleared by hardware upon entry into the service routine, regardless of how many channel interrupts were active. however, it will be set again if during execution of the service routine a new channel interrupt request is generated. note: please refer to the general interrupt control register description for an explanation of the control fields. pwmic pwm intr. ctrl. reg. esfr (f17e h /bf h ) reset value: - - 00 h 1514131211109876543210 pwm ir pwm ie ilvl glvl - - - - - - - - rwh rw rw rw
c167cs derivatives the pulse width modulation module users manual 17-15 v2.0, 2000-07 17.4 pwm output signals the output signals of the four pwm channels (pout3 pout0) are alternate output functions on port 7 (p7.3 p7.0). the output signal of each pwm channel is individually enabled by control bit penx in register pwmcon1. the pwm signals are xored with the respective port latch outputs before being driven to the port pins. this allows driving the pwm signal directly to the port pin (p7.x = 0) or drive the inverted pwm signal (p7.x = 1). figure 17-7 pwm output signal generation note: using the open drain mode on port 7 allows the combination of two or more pwm outputs through a wired-and configuration, using an external pullup device. this provides sort of a burst mode for any pwm channel. mca02277 pin p7.3 xor latch p7.3 pwm 3 pin p7.2 pwm 2 xor latch p7.2 pin p7.1 pwm 1 xor latch p7.1 & pwm 0 pin p7.0 xor latch p7.0 penx pb 01
c167cs derivatives the pulse width modulation module users manual 17-16 v2.0, 2000-07 software control of the pwm outputs in an application the pwm output signals are generally controlled by the pwm module. however, it may be necessary to influence the level of the pwm output pins via software either to initialize the system or to react on some extraordinary condition, e.g. a system fault or an emergency. clearing the timer run bit ptrx stops the associated counter and leaves the respective output at its current level. the individual pwm channel outputs are controlled by comparators according to the formula: pwm output signal = [ptx] 3 [pwx shadow latch]. so whenever software changes registers ptx, the respective output will reflect the condition after the change. loading timer ptx with a value greater than or equal to the value in pwx immediately sets the respective output, a ptx value below the pwx value clears the respective output. by clearing or setting the respective port 7 output latch the pwm channel signal is driven directly or inverted to the port pin. clearing the enable bit penx disconnects the pwm channel and switches the respective port pin to the value in the port output latch. note: to prevent further pwm pulses from occurring after such a software intervention the respective counter must be stopped first.
c167cs derivatives the analog/digital converter users manual 18-1 v2.0, 2000-07 18 the analog/digital converter the c167cs provides an analog/digital converter with 10-bit resolution and a sample & hold circuit on-chip. a multiplexer selects between up to 24 analog input channels (16 standard channels as alternate functions of port 5, 8 extension channels as alternate functions of port1) either via software (fixed channel modes) or automatically (auto scan modes). to fulfill most requirements of embedded control applications the adc supports the following conversion modes: ? fixed channel single conversion produces just one result from the selected channel ? fixed channel continuous conversion repeatedly converts the selected channel ? auto scan single conversion produces one result from each of a selected group of channels ? auto scan continuous conversion repeatedly converts the selected group of channels ? wait for addat read mode start a conversion automatically when the previous result was read ? channel injection mode insert the conversion of a specific channel into a group conversion (auto scan) a set of sfrs and port pins provide access to control functions and results of the adc. figure 18-1 sfrs and port pins associated with the a/d converter mca04472 p5 addat adcon adcic ports & direction control alternate functions data registers control registers interrupt control addat a/d converter result register addat2 a/d converter channel injection result reg. adcon a/d converter control register adcic a/d converter interrupt control register (end of conversion) adeic a/d converter interrupt control register (overrun error/channel injection) adeic p5 port 5 analog input port: an0/p5.0...an15/p5.15 p5didis port 5 digital input disable register p1l port 1 input/output port (lower part): an16/p1l.0...an23/p1l.7 p1didis port 1 digital input disable register addat2 e p5didis p1l p1didis
c167cs derivatives the analog/digital converter users manual 18-2 v2.0, 2000-07 the external analog reference voltages v aref and v agnd are fixed. the separate supply for the adc reduces the interference with other digital signals. the sample time as well as the conversion time is programmable, so the adc can be adjusted to the internal resistances of the analog sources and/or the analog reference voltage supply. figure 18-2 analog/digital converter block diagram mca04471 conversion control 10-bit converter adcon adcir adeir interrupt requests result reg. addat result reg. addat2 v agnd v aref s + h mux an16 . . . an23 mux an0 . . . . . . an15
c167cs derivatives the analog/digital converter users manual 18-3 v2.0, 2000-07 18.1 mode selection and operation the analog input channels an15 an0 are alternate functions of port 5 which is an input-only port. the port 5 lines may either be used as analog or digital inputs. for pins that shall be used as analog inputs it is recommended to disable the digital input stage via register p5didis. this avoids undesired cross currents and switching noise while the (analog) input signal level is between v il and v ih . the analog input channels an23 an16 are alternate functions of port1 which is an io port. the port lines p1l.7-0 may either be used as analog inputs or digital ios. for pins that shall be used as analog inputs it is recommended to disable the digital input stage via register p1didis. this avoids undesired cross currents and switching noise while the (analog) input signal level is between v il and v ih . the functions of the a/d converter are controlled by the bit-addressable a/d converter control register adcon. its bitfields specify the analog channel to be acted upon, the conversion mode, and also reflect the status of the converter. adcon adc control register sfr (ffa0 h /d0 h ) reset value: 0000 h 1514131211109876543210 adctc adstc ad crq ad cin ad wr ad bsy ad st adx adm adch rw rw rwh rw rw rwh rwh rw rw rw bit function adch adc analog channel input selection selects the (first) adc channel which is to be converted. bit adx determines if adch selects a standard or extension channel. 1) adm adc mode selection 00: fixed channel single conversion 01: fixed channel continuous conversion 10: auto scan single conversion 11: auto scan continuous conversion adx adc extension channel control 2) 0: adch selects the standard channels an15 an0 1: adch selects the extension channels an23 an16 adst adc start bit 0: stop a running conversion 1: start conversion(s)
c167cs derivatives the analog/digital converter users manual 18-4 v2.0, 2000-07 bitfields adch and adx specify the analog input channel which is to be converted (first channel of a conversion sequence in auto scan modes). bitfield adm selects the operating mode of the a/d converter. a conversion (or a sequence) is then started by setting bit adst. clearing adst stops the a/d converter after a certain operation which depends on the selected operating mode. the busy flag (read-only) adbsy is set, as long as a conversion is in progress. the result of a conversion is stored in the result register addat, or in register addat2 for an injected conversion. note: bitfields chnr and chx of register addat are loaded by the adc to indicate, which channel the result refers to. bitfields chnr and chx of register addat2 are loaded by the cpu to select the analog channel, which is to be injected. adbsy adc busy flag 0: adc is idle 1: a conversion is active. adwr adc wait for read control adcin adc channel injection enable adcrq adc channel injection request flag adstc adc sample time control (defines the adc sample time in a certain range) 00: t bc 8 01: t bc 16 10: t bc 32 11: t bc 64 adctc adc conversion time control (defines the adc basic conversion clock f bc ) 00: f bc = f cpu / 4 01: f bc = f cpu / 2 10: f bc = f cpu / 16 11: f bc = f cpu / 8 1) the two groups of channels are handled independently. standard channels an15 an0 are selected with adch = f h 0 h and adx = 0, extension channels an23 an16 are selected with adch = 7 h 0 h and adx = 1. 2) bit adx is available only after the execution of instruction einit. before einit bit adcon.6 controls production testmodes and must remain cleared. bit function
c167cs derivatives the analog/digital converter users manual 18-5 v2.0, 2000-07 addat adc result register sfr (fea0 h /50 h ) reset value: 0000 h 1514131211109876543210 chnr chx - adres rwh rwh - rwh addat2 adc chan. inj. result reg. esfr (f0a0 h /50 h ) reset value: 0000 h 1514131211109876543210 chnr chx - adres rw rw - rwh bit function adres a/d conversion result the 10-bit digital result of the most recent conversion. chx channel extension indicator 0: chnr refers to a standard channel (an15 an0) 1: chnr referes to an extension channel (an23 an16) chnr channel number (identifies the converted analog channel) refers to standard or extension channels (see bit chx).
c167cs derivatives the analog/digital converter users manual 18-6 v2.0, 2000-07 a conversion is started by setting bit adst = 1. the busy flag adbsy will be set and the converter then selects and samples the input channel, which is specified by the channel selection field adch in register adcon. the sampled level will then be held internally during the conversion. when the conversion of this channel is complete, the 10-bit result together with the number of the converted channel is transferred into the result register addat and the interrupt request flag adcir is set. the conversion result is placed into bitfield adres of register addat. if bit adst is reset via software, while a conversion is in progress, the a/d converter will stop after the current conversion (fixed channel modes) or after the current conversion sequence (auto scan modes). setting bit adst while a conversion is running, will abort this conversion and start a new conversion with the parameters specified in adcon. note: abortion and restart (see above) are triggered by bit adst changing from 0 to 1, i.e. adst must be 0 before being set. while a conversion is in progress, the mode selection field adm and the channel selection fields adch and adx may be changed. adm will be evaluated after the current conversion. adch and adx will be evaluated after the current conversion (fixed channel modes) or after the current conversion sequence (auto scan modes). note: when selecting an extension channel (an23 an16) only write numbers within the range 0 7 to bitfield adch. higher channel numbers are not defined for extension channels and will return invalid conversions results. fixed channel conversion modes these modes are selected by programming the mode selection bitfield adm in register adcon to 00 b (single conversion) or to 01 b (continuous conversion). after starting the converter through bit adst the busy flag adbsy will be set and the channel specified in bit fields adch/adx will be converted. after the conversion is complete, the interrupt request flag adcir will be set. in single conversion mode the converter will automatically stop and reset bits adbsy and adst. in continuous conversion mode the converter will automatically start a new conversion of the channel specified in adch/adx. adcir will be set after each completed conversion. when bit adst is reset by software, while a conversion is in progress, the converter will complete the current conversion and then stop and reset bit adbsy.
c167cs derivatives the analog/digital converter users manual 18-7 v2.0, 2000-07 auto scan conversion modes these modes are selected by programming the mode selection field adm in register adcon to 10 b (single conversion) or to 11 b (continuous conversion). auto scan modes automatically convert a sequence of analog channels, beginning with the channel specified in bit fields adch/adx and ending with channel 0/channel 16, without requiring software to change the channel number. after starting the converter through bit adst, the busy flag adbsy will be set and the channel specified in bit fields adch/adx will be converted. after the conversion is complete, the interrupt request flag adcir will be set and the converter will automatically start a new conversion of the next lower channel. adcir will be set after each completed conversion. after conversion of channel 0/channel 16 the current sequence is complete. in single conversion mode the converter will automatically stop and reset bits adbsy and adst. in continuous conversion mode the converter will automatically start a new sequence beginning with the conversion of the channel specified in adch/adx. when bit adst is reset by software, while a conversion is in progress, the converter will complete the current sequence (including conversion of channel 0/channel 16) and then stop and reset bit adbsy. figure 18-3 auto scan conversion mode example # 2 result of channel: # x # 3 write addat addat full conversion of channel.. read of addat; generate interrupt request # x # 3 # 3 # 2 interrupt request overrun error # 2 # 1 result lost mca02241 # 3 # 1 # 1 # 0 addat full; channnel 0 # 0 # 3 # 3 # 2
c167cs derivatives the analog/digital converter users manual 18-8 v2.0, 2000-07 wait for addat read mode if in default mode of the adc a previous conversion result has not been read out of register addat by the time a new conversion is complete, the previous result in register addat is lost because it is overwritten by the new value, and the a/d overrun error interrupt request flag adeir will be set. in order to avoid error interrupts and the loss of conversion results especially when using continuous conversion modes, the adc can be switched to wait for addat read mode by setting bit adwr in register adcon. if the value in addat has not been read by the time the current conversion is complete, the new result is stored in a temporary buffer and the next conversion is suspended (adst and adbsy will remain set in the meantime, but no end-of-conversion interrupt will be generated). after reading the previous value from addat the temporary buffer is copied into addat (generating an adcir interrupt) and the suspended conversion is started. this mechanism applies to both single and continuous conversion modes. note: while in standard mode continuous conversions are executed at a fixed rate (determined by the conversion time), in wait for addat read mode there may be delays due to suspended conversions. however, this only affects the conversions, if the cpu (or pec) cannot keep track with the conversion rate. figure 18-4 wait for read mode example result of channel: read of addat; # x # 2 # 3 # 1 mca01970 # 0 request generate interrupt temp-latch full addat full write addat # x of channel.. conversion # 3 # 2 # 3 temp-latch hold result in 1 # 2 # 1 wait # 1 # 0 # 3 # 3 # 0
c167cs derivatives the analog/digital converter users manual 18-9 v2.0, 2000-07 channel injection mode channel injection mode allows the conversion of a specific analog channel (also while the adc is running in a continuous or auto scan mode) without changing the current operating mode. after the conversion of this specific channel the adc continues with the original operating mode. channel injection mode is enabled by setting bit adcin in register adcon and requires the wait for addat read mode (adwr = 1). the channel to be converted in this mode is specified in bitfields chnr and chx of register addat2. note: bitfields chnr and chx in addat2 are not modified by the a/d converter, but only the adres bit field. since the channel number for an injected conversion is not buffered, bitfields chnr/chx of addat2 must never be modified during the sample phase of an injected conversion, otherwise the input multiplexer will switch to the new channel. it is recommended to only change the channel number with no injected conversion running. figure 18-5 channel injection example # x-2 write addat2 int. request conversion of channel # y addat2 full read addat2 request conversion write addat; injected read addat addat full of channel.. channel injection # x-1 # x+1 # x+1 # x # x # x # x-1 # x-1 # x-2 mca01971 adeint # ... # x-4 # y # x-2 # x-3 # x-3 # x-3 # x-4 # x-4
c167cs derivatives the analog/digital converter users manual 18-10 v2.0, 2000-07 a channel injection can be triggered in two ways: ? setting of the channel injection request bit adcrq via software ? a compare or a capture event of capture/compare register cc31 of the capcom2 unit, which also sets bit adcrq. the second method triggers a channel injection at a specific time, on the occurrence of a predefined count value of the capcom timers or on a capture event of register cc31. this can be either the positive, the negative, or both the positive and the negative edge of an external signal. in addition, this option allows recording the time of occurrence of this signal. note: the channel injection request bit adcrq will be set on any interrupt request of capcom2 channel cc31, regardless whether the channel injection mode is enabled or not. it is recommended to always clear bit adcrq before enabling the channel injection mode. after the completion of the current conversion (if any is in progress) the converter will start (inject) the conversion of the specified channel. when the conversion of this channel is complete, the result will be placed into the alternate result register addat2, and a channel injection complete interrupt request will be generated, which uses the interrupt request flag adeir (for this reason the wait for addat read mode is required). note: if the temporary data register used in wait for addat read mode is full, the respective next conversion (standard or injected) will be suspended. the temporary register can hold data for addat (from a standard conversion) or for addat2 (from an injected conversion).
c167cs derivatives the analog/digital converter users manual 18-11 v2.0, 2000-07 figure 18-6 channel injection example with wait for read # y int. int. request adeint addat2 is wait until read addat2 addat2 full temp-latch full write addat addat full read addat conversion of channel.. # x-1 channel injection # x+1 # x+1 # x # x wait until addat2 is read # x-1 # x full temp-latch addat2 full of channel y conversion injected read addat2 of channel.. conversion read addat addat full write addat # x+1 channel injection # x+1 # x # x # z # x-1 # x-1 # x-1 # x mca01972 # y # x-2 write addat2 # x-2 # x-1 # x-3 # x-2 # x-3 # x-3 # ... # ... # x-3 write addat2 # y adeint request # z read # y # x-2 # x-2 # x-3 # x-2 # x-3 request request
c167cs derivatives the analog/digital converter users manual 18-12 v2.0, 2000-07 arbitration of conversions conversion requests that are activated while the adc is idle immediately trigger the respective conversion. if a conversion is requested while another conversion is currently in progress the operation of the a/d converter depends on the kind of the involved conversions (standard or injected). note: a conversion request is activated if the respective control bit (adst or adcrq) is toggled from 0 to 1, i.e. the bit must have been zero before being set. table 18-1 summarizes the adc operation in the possible situations. table 18-1 conversion arbitration conversion in progress new requested conversion standard injected standard abort running conversion, and start requested new conversion. complete running conversion, start requested conversion after that. injected complete running conversion, start requested conversion after that. complete running conversion, start requested conversion after that. bit adcrq will be 0 for the second conversion, however.
c167cs derivatives the analog/digital converter users manual 18-13 v2.0, 2000-07 18.2 conversion timing control when a conversion is started, first the capacitances of the converter are loaded via the respective analog input pin to the current analog input voltage. the time to load the capacitances is referred to as sample time. next the sampled voltage is converted to a digital value in successive steps, which correspond to the resolution of the adc. during these phases (except for the sample time) the internal capacitances are repeatedly charged and discharged via pins v aref and v agnd . the current that has to be drawn from the sources for sampling and changing charges depends on the time that each respective step takes, because the capacitors must reach their final voltage level within the given time, at least with a certain approximation. the maximum current, however, that a source can deliver, depends on its internal resistance. the time that the two different actions during conversion take (sampling, and converting) can be programmed within a certain range in the c167cs relative to the cpu clock. the absolute time that is consumed by the different conversion steps therefore is independent from the general speed of the controller. this allows adjusting the a/d converter of the c167cs to the properties of the system: fast conversion can be achieved by programming the respective times to their absolute possible minimum. this is preferable for scanning high frequency signals. the internal resistance of analog source and analog supply must be sufficiently low, however. high internal resistance can be achieved by programming the respective times to a higher value, or the possible maximum. this is preferable when using analog sources and supply with a high internal resistance in order to keep the current as low as possible. the conversion rate in this case may be considerably lower, however. the conversion time is programmed via the upper two bits of register adcon. bitfield adctc (conversion time control) selects the basic conversion clock ( f bc ), used for the operation of the a/d converter. the sample time is derived from this conversion clock. table 18-2 lists the possible combinations. the timings refer to cpu clock cycles, where t cpu = 1 / f cpu . the limit values for f bc (see data sheet) must not be exceeded when selecting adctc and f cpu . table 18-2 adc conversion timing control adcon.15|14 (adctc) a/d converter basic clock f bc adcon.13|12 (adstc) sample time t s 00 f cpu / 4 00 t bc 8 01 f cpu / 2 01 t bc 16 10 f cpu / 16 10 t bc 32 11 f cpu / 8 11 t bc 64
c167cs derivatives the analog/digital converter users manual 18-14 v2.0, 2000-07 the time for a complete conversion includes the sample time t s , the conversion itself and the time required to transfer the digital value to the result register (2 t cpu ) as shown in the example below. note: the non-linear decoding of bit field adctc provides compatibility with 80c166 designs for the default value (00 after reset). converter timing example assumptions: f cpu = 25 mhz (i.e. t cpu = 40 ns), adctc = 00, adstc = 00. basic clock f bc = f cpu / 4 = 6.25 mhz, i.e. t bc = 160 ns. sample time t s = t bc 8 = 1280 ns. conversion time t c = t s + 40 t bc + 2 t cpu = (1280 + 6400 + 80) ns = 7.76 m s. note: for the exact specification please refer to the data sheet of the selected derivative.
c167cs derivatives the analog/digital converter users manual 18-15 v2.0, 2000-07 18.3 a/d converter interrupt control at the end of each conversion, interrupt request flag adcir in interrupt control register adcic is set. this end-of-conversion interrupt request may cause an interrupt to vector adcint, or it may trigger a pec data transfer which reads the conversion result from register addat e.g. to store it into a table in the internal ram for later evaluation. the interrupt request flag adeir in register adeic will be set either, if a conversion result overwrites a previous value in register addat (error interrupt in standard mode), or if the result of an injected conversion has been stored into addat2 (end-of-injected- conversion interrupt). this interrupt request may be used to cause an interrupt to vector adeint, or it may trigger a pec data transfer. note: please refer to the general interrupt control register description for an explanation of the control fields. adcic adc conversion intr.ctrl.reg. sfr (ff98 h /cc h ) reset value: - - 00 h 1514131211109876543210 - adc ir adc ie ilvl glvl - - - - - - - - rwh rw rw rw adeic adc error intr.ctrl.reg. sfr (ff9a h /cd h ) reset value: - - 00 h 1514131211109876543210 - ade ir ade ie ilvl glvl - - - - - - - - rwh rw rw rw
c167cs derivatives the on-chip can interface users manual 19-1 v2.0, 2000-07 19 the on-chip can interface note: the c167cs incorporates two can modules (can1 and can2). as the structure of the two modules is identical, this chapter mainly describes the functionality and the operation of module can1. the differences between modules can1 and can2 are described in a special section at the end of this chapter. the controller area network (can) bus with its associated protocol allows communication between a number of stations which are connected to this bus with high efficiency. efficiency in this context means: ? transfer speed (data rates of up to 1 mbit/sec can be achieved) ? data integrity (the can protocol provides several means for error checking) ? host processor unloading (the controller here handles most of the tasks autonomously) ? flexible and powerful message passing (the extended can protocol is supported) the integrated can module handles the completely autonomous transmission and reception of can frames in accordance with the can specification v2.0 part b (active), i.e. the on-chip can module can receive and transmit: ? standard frames with 11-bit identifiers, as well as ? extended frames with 29-bit identifiers. note: the can module is an xbus peripheral and therefore requires bit xpen in register syscon to be set in order to be operable.
c167cs derivatives the on-chip can interface users manual 19-2 v2.0, 2000-07 figure 19-1 registers associated with the can module the bit timing is derived from the xclk and is programmable up to a data rate of 1 mbaud. the minimum cpu clock frequency to achieve 1 mbaud is f cpu 3 8/16 mhz, depending on the activation of the can modules clock prescaler. the can module uses two pins of port 4 or of port 8 to interface to a bus transceiver. it provides full can functionality on up to 15 full-sized message objects (8 data bytes each). message object 15 may be configured for basic can functionality with a double- buffered receive object. both modes provide separate masks for acceptance filtering which allows the acceptance of a number of identifiers in full can mode and also allows disregarding a number of identifiers in basic can mode. all message objects can be updated independent from the other objects during operation of the module and are equipped with buffers for the maximum message length of 8 bytes. mca04473 syscon csr mcrn xp0ic core registers control registers (within each module) object registers (within each module) interrupt control csr control / status register pcir port control / interrupt register btr bit timing register gms global mask short u/lgml global mask long u/lmlm last message mask mcrn configuration register of message n u/larn arbitration register of message n xp1ic e xx uarn x larn x e syscon system configuration register syscon3 peripheral management control reg. dp4 port 4 direction control register odp4 port 4 open drain control register dp8 port 8 direction control register odp8 port 8 open drain control register xp0ic can1 interrupt control register xp1ic can2 interrupt control register data x pcir x btr x gms x u/lgml x u/lmlm x syscon3 dp4 odp4 dp8 odp8 e e e
c167cs derivatives the on-chip can interface users manual 19-3 v2.0, 2000-07 19.1 functional blocks of the can module the can module combines several functional blocks (see figure 19-2 ) that work in parallel and contribute to the controllers performance. these units and the functions they provide are described below. each of the message objects has a unique identifier and its own set of control and status bits. each object can be configured with its direction as either transmit or receive, except the last message which is only a double receive buffer with a special mask register. an object with its direction set as transmit can be configured to be automatically sent whenever a remote frame with a matching identifier (taking into account the respective global mask register) is received over the can bus. by requesting the transmission of a message with the direction set as receive, a remote frame can be sent to request that the appropriate object be sent by some other node. each object has separate transmit and receive interrupts and status bits, giving the cpu full flexibility in detecting when a remote/data frame has been sent or received. for general purpose two masks for acceptance filtering can be programmed, one for identifiers of 11 bits and one for identifiers of 29 bits. however the cpu must configure bit xtd (normal or extended frame identifier) for each valid message to determine whether a standard or extended frame will be accepted. the last message object has its own programmable mask for acceptance filtering, allowing a large number of infrequent objects to be handled by the system. the object layer architecture of the can controller is designed to be as regular and orthogonal as possible. this makes it easy to use.
c167cs derivatives the on-chip can interface users manual 19-4 v2.0, 2000-07 figure 19-2 can controller block diagram mcb04391 status register interrupt register tx/rx shift register messages messages handlers status + control eml crc btl timing generator clocks (to all) control btl - configuration can_rxd can_txd to xbus intelligent memory bsp
c167cs derivatives the on-chip can interface users manual 19-5 v2.0, 2000-07 tx/rx shift register the transmit/receive shift register holds the destuffed bit stream from the bus line to allow the parallel access to the whole data or remote frame for the acceptance match test and the parallel transfer of the frame to and from the intelligent memory. bit stream processor the bit stream processor (bsp) is a sequencer controlling the sequential data stream between the tx/rx shift register, the crc register, and the bus line. the bsp also controls the eml and the parallel data stream between the tx/rx shift register and the intelligent memory such that the processes of reception, arbitration, transmission, and error signalling are performed according to the can protocol. note that the automatic retransmission of messages which have been corrupted by noise or other external error conditions on the bus line is handled by the bsp. cyclic redundancy check register this register generates the cyclic redundancy check (crc) code to be transmitted after the data bytes and checks the crc code of incoming messages. this is done by dividing the data stream by the code generator polynomial. error management logic the error management logic (eml) is responsible for the fault confinement of the can device. its counters, the receive error counter and the transmit error counter, are incremented and decremented by commands from the bit stream processor. according to the values of the error counters, the can controller is set into the states error active , error passive and busoff . the can controller is error active , if both error counters are below the error passive limit of 128. it is error passive , if at least one of the error counters equals or exceeds 128. it goes busoff , if the transmit error counter equals or exceeds the busoff limit of 256. the device remains in this state, until the busoff recovery sequence is finished. additionally, there is the bit ewrn in the status register, which is set, if at least one of the error counters equals or exceeds the error warning limit of 96. ewrn is reset, if both error counters are less than the error warning limit.
c167cs derivatives the on-chip can interface users manual 19-6 v2.0, 2000-07 bit timing logic this block (btl) monitors the busline input can_rxd and handles the busline related bit timing according to the can protocol. the btl synchronizes on a recessive to dominant busline transition at start of frame (hard synchronization) and on any further recessive to dominant busline transition, if the can controller itself does not transmit a dominant bit (resynchronization). the btl also provides programmable time segments to compensate for the propagation delay time and for phase shifts and to define the position of the sample point in the bit time. the programming of the btl depends on the baudrate and on external physical delay times. intelligent memory the intelligent memory (cam/ram array) provides storage for up to 15 message objects of maximum 8 data bytes length. each of these objects has a unique identifier and its own set of control and status bits. after the initial configuration, the intelligent memory can handle the reception and transmission of data without further cpu actions. organization of registers and message objects all registers and message objects of the can controller are located in the special can address area of 256 bytes, which is mapped into segment 0 and uses addresses 00ef00 h through 00efff h . all registers are organized as 16-bit registers, located on word addresses. however, all registers may be accessed bytewise in order to select special actions without effecting other mechanisms. register naming reflects the specific name of a register as well as a general module indicator. this results in unique register names. example : module indicator is c1 (can module 1), specific name is control/status register ( csr ), unique register name is c1csr . note: the address map shown below lists the registers which are part of the can controller. there are also c167cs specific registers that are associated with the can module.
c167cs derivatives the on-chip can interface users manual 19-7 v2.0, 2000-07 figure 19-3 can module address map eff0 h ef0c h message object 15 message object 14 efe0 h efd0 h message object 13 message object 12 efc0 h efb0 h message object 11 message object 10 efa0 h ef90 h message object 9 message object 8 ef80 h ef70 h message object 7 message object 6 ef60 h ef50 h message object 5 message object 4 ef40 h ef30 h message object 3 message object 2 ef20 h ef10 h message object 1 general registers ef00 h mask of last message lmlm umlm lgml ugml global mask long ef08 h ef06 h global mask short gms bit timing register btr ef04 h interrupt register ir ef02 h control/status register csr ef00 h can address area general registers mca04392
c167cs derivatives the on-chip can interface users manual 19-8 v2.0, 2000-07 19.2 general functional description the control/status register (csr) accepts general control settings for the module and provides general status information. csr control/status register xreg (ef00 h ) reset value: xx01 h 1514131211109876543210 b off e wrn - rx ok tx ok lec tm cce 0 cps eie sie ie init rh rh r rwh rwh rwh rw rw r rw rw rw rw rwh bit function (control bits) init initialization starts the initialization of the can controller, when set. init is set C after a reset C when entering the busoff state C by the application software ie interrupt enable enables or disables interrupt generation from the can module via the signal xintr . does not affect status updates. sie status change interrupt enable enables or disables interrupt generation when a message transfer (reception or transmission) is successfully completed or a can bus error is detected (and registered in the status partition). eie error interrupt enable enables or disables interrupt generation on a change of bit boff or ewarn in the status partition). cps clock prescaler control bit 0: standard mode: the input clock is divided 2:1. the minimum input frequency to achieve a baudrate of 1 mbaud is f cpu = 16 mhz. 1: fast mode: the input clock is used directly 1:1. the minimum input frequency to achieve a baudrate of 1 mbaud is f cpu = 8 mhz. cce configuration change enable allows or inhibits cpu access to the bit timing register. tm test mode (must be 0) make sure that this bit is always cleared when writing to the control register, as this bit controls a special test mode, that is used for production testing. during normal operation, however, this test mode may lead to undesired behaviour of the device.
c167cs derivatives the on-chip can interface users manual 19-9 v2.0, 2000-07 note: reading the upper half of the control register (status partition) will clear the status change interrupt value in the interrupt register, if it is pending. use byte accesses to the lower half to avoid this. lec last error code this field holds a code which indicates the type of the last error occurred on the can bus. if a message has been transferred (reception or transmission) without error, this field will be cleared. 0 no error 1 stuff error: more than 5 equal bits in a sequence have occurred in a part of a received message where this is not allowed. 2 form error: wrong format in fixed format part of a received frame. 3 ackerror: the message this can controller transmitted was not acknowledged by another node. 4 bit1error: during the transmission of a message (with the exception of the arbitration field), the device wanted to send a recessive level (1), but the monitored bus value was dominant . 5 bit0error: during the transmission of a message (or acknowledge bit, active error flag, or overload flag), the device wanted to send a dominant level (0), but the monitored bus value was recessive . during busoff recovery this status is set each time a sequence of 11 recessive bits has been monitored. this enables the cpu to monitor the proceeding of the busoff recovery sequence (indicates that the bus is not stuck at dominant or continously disturbed). 6 crcerror: the received crc check sum was incorrect. 7 unused code: may be written by the cpu to check for updates. txok transmitted message successfully indicates that a message has been transmitted successfully (error free and acknowledged by at least one other node), since this bit was last reset by the cpu (the can controller does not reset this bit!). rxok received message successfully this bit is set each time a message has been received successfully, since this bit was last reset by the cpu (the can controller does not reset this bit!). rxok is also set when a message is received that is not accepted (i.e. stored). ewrn error warning status indicates that at least one of the error counters in the eml has reached the error warning limit of 96. boff busoff status indicates when the can controller is in busoff state (see eml). bit function (control bits)
c167cs derivatives the on-chip can interface users manual 19-10 v2.0, 2000-07 19.2.1 can interrupt handling the on-chip can module has one interrupt output, which is connected (through a synchronization stage) to a standard interrupt node in the c167cs in the same manner as all other interrupts of the standard on-chip peripherals. with this configuration, the user has all control options available for this interrupt, such as enabling/disabling, level and group priority, and interrupt or pec service (see note below). the on-chip can module is connected to an xbus interrupt control register. as for all other interrupts, the node interrupt request flag is cleared automatically by hardware when this interrupt is serviced (either by standard interrupt or pec service). note: as a rule, can interrupt requests can be serviced by a pec channel. however, because pec channels only can execute single predefined data transfers (there are no conditional pec transfers), pec service can only be used, if the respective request is known to be generated by one specific source, and that no other interrupt request will be generated in between. in practice this seems to be a rare case. since an interrupt request of the can module can be generated due to different conditions, the appropriate can interrupt status register must be read in the service routine to determine the cause of the interrupt request. the interrupt identifier intid (a number) in the port control/interrupt register (pcir) indicates the cause of an interrupt. when no interrupt is pending, the identifier will have the value 00 h . if the value in intid is not 00 h , then there is an interrupt pending. if bit ie in the control/ status register is set also the interrupt signal to the cpu is activated. the interrupt signal (to the interrupt node) remains active until intid gets 00 h (i.e. all interrupt requests have been serviced) or until interrupt generation is disabled (csr.ie = 0). note: the interrupt node is activated only upon a 0 ? 1 transition of the can interrupt signal. the can interrupt service routine should only be left after intid has been verified to be 00 h . the interrupt with the lowest number has the highest priority. if a higher priority interrupt (lower number) occurs before the current interrupt is processed, intid is updated and the new interrupt overrides the last one. intid is also updated when the respective source request has been processed. this is indicated by clearing the intpnd flag in the respective objects message control register (mcrn) or by reading the status partition of register csr (in case of a status change interrupt). the updating of intid is done by the can state machine and takes up to 6 can clock cycles (1 can clock cycle = 1 or 2 cpu clock cycles, determined by the prescaler bit cps), depending on current state of the state machine. note: a worst case condition can occur when brp = 00 h and the can controller is storing a just received message and the cpu is executing consecutive accesses to the can module. in this rare case the maximum delay may be 26 can clock cycles. the impact of this delay can be minimized by clearing bit intpnd at an early
c167cs derivatives the on-chip can interface users manual 19-11 v2.0, 2000-07 stage of interrupt processing, and (if required) restricting cpu accesses to the can module until the anticipated updating is complete. pcir port control / interrupt register xreg (ef02 h ) reset value: xxxx h 1514131211109876543210 - reserved - ipc intid - - - - - rw rh bit function intid interrupt identifier this number indicates the cause of the interrupt (if pending). 00 h interrupt idle: there is no interrupt request pending. 01 h status change interrupt: the can controller has updated (not necessarily changed) the status in the control register. this can refer to a change of the error status of the can controller (eie is set and boff or ewrn change) or to a can transfer incident (sie must be set), like reception or transmission of a message (rxok or txok is set) or the occurrence of a can bus error (lec is updated). the cpu may clear rxok, txok, and lec, however, writing to the status partition of the control register can never generate or reset an interrupt. to update the intid value the status partition of the control register must be read. 02 h message 15 interrupt: bit intpnd in the message control register of message object 15 (last message) has been set. the last message object has the highest interrupt priority of all message objects. 1) 1) bit intpnd of the corresponding message object has to be cleared to give messages with a lower priority the possibility to update intid or to reset intid to 00 h (idle state). (02 + n) message n interrupt: bit intpnd in the message control register of message object n has been set (n = 1 14). note that a message interrupt code is only displayed, if there is no other interrupt request with a higher priority. 1) example: message 1: intid = 03 h , message 14: intid = 10 h ipc interface port control (reset value = 111 b , i.e. no port connection) the encoding of bitfield ipc is described in section 19.7 . note: bitfield ipc can be written only while bit cce is set.
c167cs derivatives the on-chip can interface users manual 19-12 v2.0, 2000-07 19.2.2 configuration of the bit timing according to the can protocol specification, a bit time is subdivided into four segments: sync segment, propagation time segment, phase buffer segment 1 and phase buffer segment 2. each segment is a multiple of the time quantum t q , with t q = (brp + 1) 2 (1 C cps) t xclk . note: the can module is connected to the cpu clock signal, therefore t xclk = t cpu . the synchronization segment (sync seg) is always 1 t q long. the propagation time segment and the phase buffer segment 1 (combined to tseg1) define the time before the sample point, while phase buffer segment 2 (tseg2) defines the time after the sample point. the length of these segments is programmable (except sync-seg) via the bit timing register (btr). note: for exact definition of these segments please refer to the can protocol specification. figure 19-4 bit timing definition the bit time is determined by the xbus clock period t xclk , the baud rate prescaler, and the number of time quanta per bit: bit time = t sync-seg + t tseg1 + t tseg2 [19.1] t sync-seg = 1 t q t tseg1 = (tseg1 + 1) t q t tseg2 = (tseg2 + 1) t q t q = (brp + 1) 2 (1-cps) t xclk [19.2] note: tseg1, tseg2, and brp are the programmed numerical values from the respective fields of the bit timing register. mct04393 sync- seg 1 time quantum ( t q ) tseg1 sample point sync- seg tseg2 transmit point 1 bit time
c167cs derivatives the on-chip can interface users manual 19-13 v2.0, 2000-07 note: this register can only be written, if the config. change enable bit (cce) is set. hard synchronization and resynchronization to compensate phase shifts between clock oscillators of different can controllers, any can controller has to synchronize on any edge from recessive to dominant bus level if the edge lies between a sample point and the next synchronization segment, and on any other edge if it itself does not send a dominant level. if the hard synchronization is enabled (at the start of frame), the bit time is restarted at the synchronization segment, otherwise the resynchronization jump width (sjw) defines the maximum number of time quanta by which a bit time may be shortened or lengthened during one resynchronization. the current bit time is adjusted by t sjw = (sjw + 1) t q note: sjw is the programmed numerical value from the respective field of the bit timing register. btr bit timing register xreg (ef04 h ) reset value: uuuu h 1514131211109876543210 0 tseg2 tseg1 sjw brp r rw rw rw rw bit function brp baud rate prescaler for generating the bit time quanta the cpu frequency f cpu is divided by 2 (1 C cps) (brp + 1). see also the prescaler control bit cps in register csr. sjw (re)synchronization jump width adjust the bit time by maximum (sjw + 1) time quanta for resynchronization. tseg1 time segment before sample point there are (tseg1 + 1) time quanta before the sample point. valid values for tseg1 are 2 15. tseg2 time segment after sample point there are (tseg2 + 1) time quanta after the sample point. valid values for tseg2 are 1 7.
c167cs derivatives the on-chip can interface users manual 19-14 v2.0, 2000-07 calculation of the bit time the programming of the bit time according to the can specification depends on the desired baudrate, the xclk frequency, and on the external physical delay times of the bus driver, of the bus line and of the input comparator. these delay times are summarized in the propagation time segment t prop , where t prop is two times the maximum of the sum of physical bus delay, the input comparator delay, and the output driver delay rounded up to the nearest multiple of t q . to fulfill the requirements of the can specification, the following conditions must be met: t tseg2 3 2 t q = information processing time t tseg2 3 t sjw t tseg1 3 3 t q t tseg1 3 t sjw + t prop note: in order to achieve correct operation according to the can protocol the total bit time should be at least 8 t q , i.e. tseg1 + tseg2 3 5. so, to operate with a baudrate of 1 mbit/sec, the xclk frequency has to be at least 8/16 mhz (depending on the prescaler control bit cps in register csr). the maximum tolerance df for xclk depends on the phase buffer segment 1 (pb1), the phase buffer segment 2 (pb2), and the resynchronization jump width (sjw): df and df the examples below show how the bit timing is to be calculated under specific circumstances. min pb1 pb2 , () 2 13 bit time pb2 C () --------------------------------------------------------------- - t sjw 20 bit time ------------------------------- -
c167cs derivatives the on-chip can interface users manual 19-15 v2.0, 2000-07 bit timing example for high baudrate this example makes the following assumptions: ? xclk frequency = 20 mhz ? brp = 00, cps = 0 ? baudrate = 1 mbit/sec t q 100 ns = 2 t xclk bus driver delay 50 ns receiver circuit delay 30 ns bus line (40 m) delay 220 ns t prop 600 ns = 6 t q t sjw 100 ns = 1 t q t tseg1 700 ns = t prop + t sjw t tseg2 200 ns = information processing time t sync 100 ns = 1 t q t bit 1000 ns = t sync + t tseg1 + t tseg2 tolerance for t xclk 0.39% = = bit timing example for low baudrate this example makes the following assumptions: ? xclk frequency = 4 mhz ? brp = 01, cps = 0 ? baudrate = 100 kbit/sec t q 1 m s= 4 t xclk bus driver delay 200 ns receiver circuit delay 80 ns bus line (40 m) delay 220 ns t prop 1 m s= 1 t q t sjw 4 m s= 4 t q t tseg1 5 m s= t prop + t sjw t tseg2 4 m s= information processing time + 2 t q t sync 1 m s= 1 t q t bit 10 m s= t sync + t tseg1 + t tseg2 tolerance for f xclk 1.58% = = min pb1 pb2 , () 2 13 bit time pb2 C () --------------------------------------------------------------- - 0,1 m s 2131 m s0,2 m s C () ----------------------------------------------------------- min pb1 pb2 , () 2 13 bit time pb2 C () --------------------------------------------------------------- - 4 m s 21310 m s4 m s C () ---------------------------------------------------------
c167cs derivatives the on-chip can interface users manual 19-16 v2.0, 2000-07 19.2.3 mask registers messages can use standard or extended identifiers. incoming frames are masked with their appropriate global masks. bit ide of the incoming message determines, if the standard 11-bit mask in global mask short (gms) is to be used, or the 29-bit extended mask in global mask long (ugml&lgml). bits holding a 0 mean dont care, i.e. do not compare the messages identifier in the respective bit position. the last message object (15) has an additional individually programmable acceptance mask (mask of last message, umlm&lmlm) for the complete arbitration field. this allows classes of messages to be received in this object by masking some bits of the identifier. note: the mask of last message is anded with the global mask that corresponds to the incoming message. gms global mask short xreg (ef06 h ) reset value: ufuu h 1514131211109876543210 id20 18 11111 id28 21 rw r r r r r rw bit function id28 18 identifier (11-bit) mask to filter incoming messages with standard identifier.
c167cs derivatives the on-chip can interface users manual 19-17 v2.0, 2000-07 ugml upper global mask long xreg (ef08 h ) reset value: uuuu h 1514131211109876543210 id20 13 id28 21 rw rw lgml lower global mask long xreg (ef0a h ) reset value: uuuu h 1514131211109876543210 id4 0 000 id12 5 rw r r r rw bit function id28 0 identifier (29-bit) mask to filter incoming messages with extended identifier.
c167cs derivatives the on-chip can interface users manual 19-18 v2.0, 2000-07 umlm upper mask of last message xreg (ef0c h ) reset value: uuuu h 1514131211109876543210 id20 18 id17 13 id28 21 rw rw rw lmlm lower mask of last message xreg (ef0e h ) reset value: uuuu h 1514131211109876543210 id4 0 000 id12 5 rw r r r rw bit function id28 0 identifier (29-bit) mask to filter the last incoming message (nr. 15) with standard or extended identifier (as configured).
c167cs derivatives the on-chip can interface users manual 19-19 v2.0, 2000-07 19.3 the message object the message object is the primary means of communication between cpu and can controller. each of the 15 message objects uses 15 consecutive bytes (see figure 19-5 ) and starts at an address that is a multiple of 16. note: all message objects must be initialized by the cpu, even those which are not going to be used, before clearing the init bit. figure 19-5 message object address map the general properties of a message object are defined via the message control register (mcr). there is a dedicated register mcrn for each message object n. each element of the message control register is made of two complementary bits.this special mechanism allows the selective setting or resetting of specific elements (leaving others unchanged) without requiring read-modify-write cycles. none of these elements will be affected by reset. table 19-1 shows how to use and interpret these 2-bit fields. table 19-1 mcr bitfield encoding value function on write meaning on read 0 0 C reserved C C reserved C 0 1 reset element element is reset 1 0 set element element is set 1 1 leave element unchanged C reserved C mca04394 msg. config. ( mcfg ) data0 arbitration ( uar & lar ) message control ( mcr ) data1 data2 data3 data4 data5 data6 data7 reserved +0 +2 +4 +6 +8 +10 +12 +14 offset object start address (efn0 h ) message object 1: ef10 h message object 2: ef20 h ... message object 14: efe0 h message object 15: eff0 h
c167cs derivatives the on-chip can interface users manual 19-20 v2.0, 2000-07 mcrn message control register xreg (efn0 h ) reset value: uuuu h 1514131211109876543210 rmtpnd txrq msglst cpuupd newdat msgval txie rxie intpnd rw rw rw rw rw rw rw rw bit function intpnd interrupt pending indicates, if this message object has generated an interrupt request (see txie and rxie), since this bit was last reset by the cpu, or not. rxie receive interrupt enable defines, if bit intpnd is set after successful reception of a frame. txie transmit interrupt enable defines, if bit intpnd is set after successful transmission of a frame. 1) msgval message valid indicates, if the corresponding message object is valid or not. the can controller only operates on valid objects. message objects can be tagged invalid, while they are changed, or if they are not used at all. newdat new data indicates, if new data has been written into the data portion of this message object by cpu (transmit-objects) or can controller (receive- objects) since this bit was last reset, or not. 2) msglst message lost (this bit applies to receive -objects only!) indicates that the can controller has stored a new message into this object, while newdat was still set, i.e. the previously stored message is lost. cpuupd cpu update (this bit applies to transmit -objects only!) indicates that the corresponding message object may not be transmitted now. the cpu sets this bit in order to inhibit the transmission of a message that is currently updated, or to control the automatic response to remote requests. txrq transmit request indicates that the transmission of this message object is requested by the cpu or via a remote frame and is not yet done. txrq can be disabled by cpuupd. 1)3)
c167cs derivatives the on-chip can interface users manual 19-21 v2.0, 2000-07 1) in message object 15 (last message) these bits are hardwired to 0 (inactive) in order to prevent transmission of message 15. 2) when the can controller writes new data into the message object, unused message bytes will be overwritten by non specified values. usually the cpu will clear this bit before working on the data, and verify that the bit is still cleared once it has finished working to ensure that it has worked on a consistent set of data and not part of an old message and part of the new message. for transmit-objects the cpu will set this bit along with clearing bit cpuupd. this will ensure that, if the message is actually being transmitted during the time the message was being updated by the cpu, the can controller will not reset bit txrq. in this way bit txrq is only reset once the actual data has been transferred. 3) when the cpu requests the transmission of a receive-object, a remote frame will be sent instead of a data frame to request a remote node to send the corresponding data frame. this bit will be cleared by the can controller along with bit rmtpnd when the message has been successfully transmitted, if bit newdat has not been set. if there are several valid message objects with pending transmission request, the message with the lowest message number is transmitted first. this arbitration is done when several objects are requested for transmission by the cpu, or when operation is resumed after an error frame or after arbitration has been lost. arbitration registers the arbitration registers (uarn&larn) are used for acceptance filtering of incoming messages and to define the identifier of outgoing messages. a received message with a matching identifier is accepted as a data frame (matching object has dir = 0) or as a remote frame (matching object has dir = 1). for matching, the corresponding global mask has to be considered (in case of message object 15 also the mask of last message). extended frames (using global mask long) can be stored only in message objects with xtd = 1, standard frames (using global mask short) only in message objects with xtd = 0. message objects should have unique identifiers, i.e. if some bits are masked out by the global mask registers (i.e. dont care), then the identifiers of the valid message objects should differ in the remaining bits which are used for acceptance filtering. if a received message (data frame or remote frame) matches with more than one valid message object, it is associated with the object with the lowest message number. i.e. a received data frame is stored in the lowest object, or the lowest object is sent in response to a remote frame. the global mask is used for matching here. rmtpnd remote pending (used for transmit-objects) indicates that the transmission of this message object has been requested by a remote node, but the data has not yet been transmitted. when rmtpnd is set, the can controller also sets txrq. rmtpnd and txrq are cleared, when the message object has been successfully transmitted. bit function
c167cs derivatives the on-chip can interface users manual 19-22 v2.0, 2000-07 after a transmission (data frame or remote frame) the transmit request flag of the matching object with the lowest message number is cleared. the global mask is not used in this case. when the can controller accepts a data frame , the complete message is stored into the corresponding message object, including the identifier (also masked bits, standard identifiers have bits id17-0 filled with 0), the data length code (dlc), and the data bytes (valid bytes indicated by dlc). this is implemented to keep the data bytes connected with the identifier, even if arbitration mask registers are used. when the can controller accepts a remote frame , the corresponding transmit message object (1 14) remains unchanged, except for bits txrq and rmtpnd, which are set, of course. in the last message object 15 (which cannot start a transmission) the identifier bits corresponding to the dont care bits of the last message mask are copied from the received frame. bits corresponding to the dont care bits of the corresponding global mask are not copied (i.e. bits masked out by the global and the last message mask cannot be retrieved from object 15). uarn upper arbitration register xreg (efn2 h ) reset value: uuuu h 1514131211109876543210 id20 18 id17 13 id28 21 rw rw larn lower arbitration register xreg (efn4 h ) reset value: uuuu h 1514131211109876543210 id4 0 000 id12 5 rw r r r rw bit function id28 0 identifier (29-bit) identifier of a standard message (id28 18) or an extended message (id28 0). for standard identifiers bits id17 0 are dont care.
c167cs derivatives the on-chip can interface users manual 19-23 v2.0, 2000-07 message configuration the message configuration register (low byte of mcfgn) holds a description of the message within this object. note: there is no dont care option for bits xtd and dir. so incoming frames can only match with corresponding message objects, either standard (xtd = 0) or extended (xtd = 1). data frames only match with receive-objects, remote frames only match with transmit-objects. when the can controller stores a data frame, it will write all the eight data bytes into a message object. if the data length code was less than 8, the remaining bytes of the message object will be overwritten by non specified values. note: the first data byte occupies the upper half of the message configuration register. mcfgn message configuration reg. xreg (efn6 h ) reset value: - - uu h 1514131211109876543210 data byte 0 dlc dir xtd 0 0 rw rw rw rw r r bit function xtd extended identifier 0: standard this message object uses a standard 11-bit identifier. 1: extended this message object uses an extended 29-bit identifier. dir message direction 0: receive object on txrq, a remote frame with the identifier of this message object is transmitted. on reception of a data frame with matching identifier, that message is stored in this message object. 1: transmit object on txrq, the respective message object is transmitted. on reception of a remote frame with matching identifier, the txrq and rmtpnd bits of this message object are set. dlc data length code defines the number of valid data bytes within the data area. valid values for the data length are 0 8.
c167cs derivatives the on-chip can interface users manual 19-24 v2.0, 2000-07 data area the data area occupies 8 successive byte positions after the message configuration register, i.e. the data area of message object n covers locations 00efn7 h through 00efne h . location 00efnf h is reserved. message data for message object 15 (last message) will be written into a two-message- alternating buffer to avoid the loss of a message, if a second message has been received, before the cpu has read the first one. handling of message objects the following diagrams summarize the actions that have to be taken in order to transmit and receive messages over the can bus. the actions taken by the can controller are described as well as the actions that have to be taken by the cpu (i.e. the servicing program). the diagrams show: ? can controller handling of transmit objects ? can controller handling of receive objects ? cpu handling of transmit objects ? cpu handling of receive objects ? cpu handling of last message object ? handling of the last messages alternating buffer
c167cs derivatives the on-chip can interface users manual 19-25 v2.0, 2000-07 figure 19-6 can controller handling of transmit objects (dir = 1) mca04395 received remote frame with same identifier as this message object? txrq = 1 cpuupd = 0 transmission successful? bus free? yes newdat := 0 load message into buffer send message yes txie = 1? yes intpnd := 1 no no yes rxie = 1? yes intpnd := 1 no txrq := 1 rmtpnd := 1 no no 0: reset 1: set yes no newdat = 1? txrq := 0 rmtpnd := 0 no yes
c167cs derivatives the on-chip can interface users manual 19-26 v2.0, 2000-07 figure 19-7 can controller handling of receive objects (dir = 0) mca04396 received frame with same identifier as this message object? txrq = 1? cpuupd = 0? transmission successful? bus idle? yes newdat := 0 load identifier and control into buffer send remote frame yes txrq := 0 rmtpnd := 0 txie = 1? yes intpnd := 1 no no yes newdat = 1 no rxie = 1? yes intpnd := 1 no store message newdat := 1 txrq := 0 rmtpnd := 0 yes msglst := 1 no no 0: reset 1: set yes no
c167cs derivatives the on-chip can interface users manual 19-27 v2.0, 2000-07 figure 19-8 cpu handling of transmit objects (dir = 1) mca04397 update message? want to send? no yes txrq := 1 no yes cpuupd := 0 write / calculate message contents cpuupd := 1 newdat := 1 txie := (application cpecific) rxie := (application cpecific) intpnd := 0 rmtpnd := 0 txrq := 0 cpuupd := 1 identifier := (application cpecific) newdat := 0 direction := transmit dlc := (application cpecific) msgval := 1 xtd := (application cpecific) (all bits undefined) update update: start update: end initialization power up 0: reset 1: set
c167cs derivatives the on-chip can interface users manual 19-28 v2.0, 2000-07 figure 19-9 cpu handling of receive objects (dir = 0) mca04398 request update? newdat = 1? no yes no process message contents newdat := 0 txie := (application cpecific) rxie := (application cpecific) intpndd := 0 rmtpnd := 0 txrq := 0 msglst := 0 identifier := (application cpecific) newdat := 0 direction := receive dlc := (value of dlc in transmitter) msgval := 1 xtd := (application cpecific) (all bits undefined) process process: start process: end initialization power up 0: reset 1: set yes txrq := 1 restart process
c167cs derivatives the on-chip can interface users manual 19-29 v2.0, 2000-07 figure 19-10 cpu handling of the last message object mca04399 newdat = 1? no yes newdat := 0 process message contents rxie := (application cpecific) intpnd := 0 rmtpnd := 0 msglst := 0 identifier := (application cpecific) newdat := 0 direction := receive dlc := (value of dlc in transmitter) msgval := 1 xtd := (application cpecific) (all bits undefined) process process: start process: end initialization power up 0: reset 1: set restart process
c167cs derivatives the on-chip can interface users manual 19-30 v2.0, 2000-07 figure 19-11 handling of the last message objects alternating buffer mca04400 buffer 1 = released buffer 2 = released cpu access to buffer 2 reset buffer 1 = released buffer 2 = allocated cpu access to buffer 2 cpu allocates buffer 2 buffer 1 = allocated buffer 2 = released cpu access to buffer 1 buffer 1 = allocated buffer 2 = allocated cpu access to buffer 2 buffer 1 = allocated buffer 2 = allocated cpu access to buffer 1 store received message into buffer 1 store received message into buffer 2 cpu releases buffer 2 cpu releases buffer 1 store received message into buffer 1 msglst is set cpu releases buffer 2 cpu releases buffer 1 store received message into buffer 2 msglst is set allocated: newdat = 1 or rmtpnd = 1 released: newdat = 0 and rmtpnd = 0 store received message into buffer 1
c167cs derivatives the on-chip can interface users manual 19-31 v2.0, 2000-07 19.4 controlling the can module the can module is controlled by the c167cs via hardware signals (e.g. reset) and via register accesses executed by software. accessing the on-chip can module the can module is implemented as an x-peripheral and is therefore accessed like an external memory or peripheral. that means that the registers of the can module can be read and written using 16-bit or 8-bit direct or indirect mem addressing modes. also bit handling is not supported via the xbus. since the xbus, to which the can module is connected, also represents the external bus, can accesses follow the same rules and procedures as accesses to the external bus. can accesses cannot be executed in parallel to external instruction fetches or data read/writes, but are arbitrated and inserted into the external bus access stream. accesses to the can module use demultiplexed addresses, a 16-bit data bus (byte accesses possible), two waitstates and no tristate waitstate. the can address area starts at 00ef00 h and covers 256 bytes. this area is decoded internally, so none of the programmable address windows must be sacrificed in order to access the on-chip can module. the advantage of locating the can address area in segment 0 is that the can module is accessible via data page 3, which is the system data page, accessed usually through the system data page pointer dpp3. in this way, the internal addresses, such like sfrs, internal ram, and the can registers, are all located within the same data page and form a contiguous address space. power down mode if the c167cs enters power down mode, the xclk signal will be turned off which will stop the operation of the can module. any message transfer is interrupted. in order to ensure that the can controller is not stopped while sending a dominant level (0) on the can bus, the cpu should set bit init in the control register prior to entering power down mode. the cpu can check if a transmission is in progress by reading bits txrq and newdat in the message objects and bit txok in the control register. after returning from power down mode via hardware reset, the can module has to be reconfigured. disabling the can modules when the can module is disabled by setting bit candisx in register syscon3 (peripheral management) no register accesses are possible. also the modules logic blocks are stopped and no can bus transfers are possible. after re-enabling the can module (candisx = 0) it must be reconfigured (as after returning from power down mode).
c167cs derivatives the on-chip can interface users manual 19-32 v2.0, 2000-07 note: incoming message frames can still be recognized (not received) in this case by monitoring the receive line canx_rxd. for this purpose the receive line canx_rxd can be connected to a fast external interrupt via register exisel. can module reset the on-chip can module is connected to the xbus reset signal. this signal is activated, when the c167css reset input is activated, when a software reset is executed, and in case of a watchdog reset. activating the can modules reset line triggers a hardware reset. this hardware reset: ? disconnects the can_txd output from the port logic ? clears the error counters ? resets the busoff state ? switches the control registers low byte to 01 h ? leaves the control registers high byte and the interrupt register undefined ? does not change the other registers including the message objects (notified as uuuu) note: the first hardware reset after power-on leaves the un changed registers in an un defined state, of course. the value 01 h in the control registers low byte prepares for the module initialization. can module activation after a reset the can module is disabled. before it can be used to receive or transmit messages the application software must activate the can module. three actions are required for this purpose: ? general module enable globally activates the can module. this is done by setting bit xpen in register syscon after setting the corresponding selection bit in register xpercon. ? pin assignment selects a pair of port pins that connect the can module to the external transceiver. this is done via bitfield ipc in register csr. ? module initialization determines the functionality of the can module (baudrate, active objects, etc.). this is the major part of the activation and is described in the following.
c167cs derivatives the on-chip can interface users manual 19-33 v2.0, 2000-07 module initialization the module initialization is enabled by setting bit init in the control register csr. this can be done by the cpu via software, or automatically by the can controller on a hardware reset, or if the eml switches to busoff state. while init is set: ? all message transfer from and to the can bus is stopped ? the can transmit line can_txd is 1 (recessive) ? the control bits newdat and rmtpnd of the last message object are reset ? the counters of the eml are left unchanged. setting bit cce in addition, permits changing the configuration in the bit timing register. to initialize the can controller, the following actions are required: ? configure the bit timing register (cce required) ? set the global mask registers ? initialize each message object. if a message object is not needed, it is sufficient to clear its message valid bit (msgval), i.e. to define it as not valid. otherwise, the whole message object has to be initialized. after the initialization sequence has been completed, the cpu clears bit init. now the bsp synchronizes itself to the data transfer on the can bus by waiting for the occurrence of a sequence of 11 consecutive recessive bits (i.e. bus idle) before it can take part in bus activities and start message transfers. the initialization of the message objects is independent of the state of bit init and can be done on the fly. the message objects should all be configured to particular identifiers or set to not valid before the bsp starts the message transfer, however. to change the configuration of a message object during normal operation, the cpu first clears bit msgval, which defines it as not valid. when the configuration is completed, msgval is set again.
c167cs derivatives the on-chip can interface users manual 19-34 v2.0, 2000-07 busoff recovery sequence if the device goes busoff , it will set bit boff and also set bit init of its own accord, stopping all bus activities. to have the can module take part in the can bus activities again, the bus-off recovery sequence must be started by clearing the bit init (via software). once init has been cleared, the module will then wait for 129 occurrences of bus idle before resuming normal operation. at the end of the busoff recovery sequence the error management counters will be reset. this will automatically clear bits boff and ewrn. during the waiting time after the resetting of init each time a sequence of 11 recessive bits has been monitored, a bit0error code is written to the control register, enabling the cpu to check up whether the can bus is stuck at dominant or continously disturbed and to monitor the proceeding of the busoff recovery sequence. note: an interrupt can be generated when entering the busoff state if bits ie and eie are set. the corresponding interrupt code in bitfield intid is 01 h . the busoff recovery sequence cannot be shortened by setting or resetting init.
c167cs derivatives the on-chip can interface users manual 19-35 v2.0, 2000-07 19.5 configuration examples for message objects the two examples below represent standard applications for using can messages. both examples assume that identifier and direction are already set up correctly. the respective contents of the message control register (mcr) are shown. configuration example of a transmission object this object shall be configured for transmission. it shall be transmitted automatically in response to remote frames, but no receive interrupts shall be generated for this object. after updating the message the cpu should clear cpuupd and set newdat. the previously received remote request will then be answered. if the cpu wants to transmit the message actively it should also set txrq (which should otherwise be left alone). mcr (data bytes are not written completely ? cpuupd = 1) 1514131211109876543210 0 10 11 00 11 00 10 10 1 rmtpnd txrq cpuupd newdat msgval txie rxie intpnd mcr (remote frame was received in the meantime ? rmtpnd = 1, txrq = 1) 1514131211109876543210 1 01 01 00 11 00 10 10 1 rmtpnd txrq cpuupd newdat msgval txie rxie intpnd
c167cs derivatives the on-chip can interface users manual 19-36 v2.0, 2000-07 configuration example of a reception object this object shall be configured for reception. a receive interrupt shall be generated each time new data comes in. from time to time the cpu sends a remote request to trigger the sending of this data from a remote node. . to process the message the cpu should clear intpnd and newdat, process the data, and check that newdat is still clear after that. if not, the processing should be repeated. to send a remote frame to request the data, simply bit txrq needs to be set. this bit will be cleared by the can controller, once the remote frame has been sent or if the data is received before the can controller could transmit the remote frame. mcr (message object is idle, i.e. waiting for a frame to be received) 1514131211109876543210 0 10 10 10 11 00 11 00 1 rmtpnd txrq msglst newdat msgval txie rxie intpnd mcr (a data frame was received ? newdat = 1, intpnd = 1) 1514131211109876543210 0 10 10 11 01 00 11 01 0 rmtpnd txrq msglst newdat msgval txie rxie intpnd
c167cs derivatives the on-chip can interface users manual 19-37 v2.0, 2000-07 19.6 the second can module can2 module can2 is basically identical with module can1. it provides the same set of message objects, operating modes, and registers. while the number, sequence, and function of the can2 registers are exactly the same as in module can1, module can2, of course, resides in a separate address window. the on-chip interrupt generation works in exactly the same way as in module can1. module can2 is connected to a separate interrupt node. so each can module can be accessed and serviced independently. it also uses a separate physical interface to connect to an external can bus (see section 19.7 ). table 19-2 can register summary register locations in module can2 register locations in module can1 c2csr ee00 h c1csr ef00 h c2pcir ee02 h c1pcir ef02 h c2btr ee04 h c1btr ef04 h c2gms ee06 h c1gms ef06 h c2ugml ee08 h c1ugml ef08 h c2lgml ee0a h c1lgml ef0a h c2umlm ee0c h c1umlm ef0c h c2lmlm ee0e h c1lmlm ef0e h c2mcrn een0 h c1mcrn efn0 h c2uarn een2 h c1uarn efn2 h c2larn een4 h c1larn efn4 h c2mcfgn een6 h c1mcfgn efn6 h data area can2 een7 h eene h data area can1 efn7 h efne h table 19-3 can interrupt connection module interrupt node interrupt flag interrupt vector can1 xp0ic xp0ir xp0int can2 xp1ic xp1ir xp1int
c167cs derivatives the on-chip can interface users manual 19-38 v2.0, 2000-07 19.7 the can application interface the on-chip can modules of the c167cs are connected to the (external) physical layer (i.e. the can bus) via two signals each: note: the two interfaces may be combined on two port pins connecting to one single can bus. a logic low level ( 0) is interpreted as the dominant can bus level, a logic high level (1) is interpreted as the recessive can bus level. connection to an external transceiver the two can modules of the c167cs can be connected to an external can bus via a can transceiver in several ways: ? separate buses permit communication on two independent can buses, e.g. with different baudrates. for this purpose the can interface lines must be assigned to separate pairs of port pins. ? a single bus can be connected, where both modules provide a total of 30 message objects. for this purpose the can interface lines must be assigned to the same pair of port pins. note: basically it is also possible to connect several can modules directly (on-board) without using can transceivers. the can modules may here reside on the same or on separate devices. table 19-4 can interface signals can signal port pin function can1_rxd controlled via c1pcir.ipc receive data from the physical layer of the can bus 1. can1_txd transmit data to the physical layer of the can bus 1. can2_rxd controlled via c2pcir.ipc receive data from the physical layer of the can bus 2. can2_txd transmit data to the physical layer of the can bus 2.
c167cs derivatives the on-chip can interface users manual 19-39 v2.0, 2000-07 figure 19-12 connection to separate can buses figure 19-13 connection to a single can bus mca04474 can transceiver physical layer c167cs can transceiver physical layer can1_txd can1_rxd can2_txd can2_rxd can bus a can bus b mca04475 can transceiver physical layer c167cs can_txd can_rxd can bus can 1 can 2 &
c167cs derivatives the on-chip can interface users manual 19-40 v2.0, 2000-07 port control the receive data line and the transmit data line of the can module are alternate port functions. make sure that the respective port pin for the receive line is switched to input in order to enable proper reception. the respective port driver for the transmit will automatically be switched on. this provides a standard pin configuration without additional software control and also works in emulation mode where the port direction registers cannot be controlled. the receive and transmit line of the can module may be assigned to several port pins of the c167cs under software control. this assignment is selected via bitfield ipc (interface port connection) in register pcir. table 19-5 assignment of can interface lines to port pins ipc can_rxd can_txd notes 000 p4.5 / p4.4 p4.6 / p4.7 module specific assignments (can1 / can2). 1) 1) this assignment is compatible with previous derivatives where the assignment of can interface lines was fixed. 001 p4.7 p4.6 pins p4.5-0 available for segment address lines a21 a16 (4 mbyte external address space). 010 p8.0 p8.1 port 4 available for segment address lines a23 a16 (16 mbyte external address space). 011 p8.2 p8.3 port 4 available for segment address lines a23 a16 (16 mbyte external address space). 100 --- --- reserved . do not use this combination. 101 --- --- reserved . do not use this combination. 110 --- --- reserved . do not use this combination. 111 idle (recessive) disconnected no port assigned. default after reset.
c167cs derivatives the on-chip can interface users manual 19-41 v2.0, 2000-07 the location of the can interface lines can now be selected via software according to the requirements of an application: compatible assignment (ipc = 000 b ) makes the c167cs suitable for applications with a given hardware (board layout). the can interface lines are connected to the port pins to which they are hardwired in previous derivatives. wide address assignment (ipc = 001 b ) uses the two upper pins of port 4, leaving room for six segment address lines (a21 a16). a contiguous external address space of 4 mbyte is available in this case. full address assignment (ipc = 010 b or 011 b ) removes the can interface lines completely from port 4. the maximum external address space of 16 mbyte is available in this case. the can interface lines are mapped to port 8. two pairs of port 8 pins can be selected. no assignment (ipc = 111 b ) disconnects the can interface lines from the port logic. this avoids undesired currents through the interface pin drivers while the c167cs is in a power saving state. after reset the can interface lines are disconnected. bus sharing internally combines the interface lines of both can modules (receive line is shared, transmit lines are anded). this provides up to 30 message objects (2 15) on a single physical can bus. bus sharing is enabled by simply assigning both can interfaces to the same pair of port pins. note: assigning can interface signals to a port pin overrides the other alternate function of the respective pin (segment address on port 4, capcom lines on port 8).
c167cs derivatives system reset users manual 20-1 v2.0, 2000-07 20 system reset the internal system reset function provides initialization of the c167cs into a defined default state and is invoked either by asserting a hardware reset signal on pin rstin (hardware reset input), upon the execution of the srst instruction (software reset) or by an overflow of the watchdog timer. whenever one of these conditions occurs, the microcontroller is reset into its predefined default state through an internal reset procedure. when a reset is initiated, pending internal hold states are cancelled and the current internal access cycle (if any) is completed. an external bus cycle is aborted, except for a watchdog reset (see description). after that the bus pin drivers and the io pin drivers are switched off (tristate). the internal reset procedure requires 516 cpu clock cycles in order to perform a complete reset sequence. this 516 cycle reset sequence is started upon a watchdog timer overflow, a srst instruction or when the reset input signal rstin is latched low (hardware reset). the internal reset condition is active at least for the duration of the reset sequence and then until the rstin input is inactive and the pll has locked (if the pll is selected for the basic clock generation). when this internal reset condition is removed (reset sequence complete, rstin inactive, pll locked) the reset configuration is latched from port0, rd , and ale (depending on the start mode). after that pins ale, rd , and wr are driven to their inactive levels. note: bit adp which selects the adapt mode is latched with the rising edge of rstin . after the internal reset condition is removed, the microcontroller will either start program execution from external or internal memory, or enter boot mode. figure 20-1 external reset circuitry reset + a) generated warm reset b) automatic power-on reset & mca04483 rstout c167cr external hardware a) b) external reset sources cc v rstin c161cs/jc/ji rstin
c167cs derivatives system reset users manual 20-2 v2.0, 2000-07 20.1 reset sources several sources (external or internal) can generate a reset for the c167cs. software can identify the respective reset source via the reset source indication flags in register wdtcon. generally any reset causes the same actions on the c167css modules. the differences are described in the following sections. hardware reset a hardware reset is triggered when the reset input signal rstin is latched low. to ensure the recognition of the rstin signal (latching), it must be held low for at least 100 ns plus 2 cpu clock cycles (input filter plus synchronization). also shorter rstin pulses may trigger a hardware reset, if they coincide with the latchs sample point. the actual minimum duration for a reset pulse depends on the current cpu clock generation mode. the worstcase is generating the cpu clock via the slowdown divider using the maximum factor while the configured basic mode uses the prescaler ( f cpu = f osc / 64 in this case). after the reset sequence has been completed, the rstin input is sampled again. when the reset input signal is inactive at that time, the internal reset condition is terminated (indicated as short hardware reset, shwr). when the reset input signal is still active at that time, the internal reset condition is prolonged until rstin gets inactive (indicated as long hardware reset, lhwr). during a hardware reset the inputs for the reset configuration (port0, rd , ale) need some time to settle on the required levels, especially if the hardware reset aborts a read operation from an external peripheral. during this settling time the configuration may intermittently be wrong. for the duration of one internal reset sequence after a reset has been recognized the configuration latches are not transparent, i.e. the (new) configuration becomes valid earliest after the completion of one reset sequence. this usually covers the required settling time. when the basic clock is generated by the pll the internal reset condition is automatically extended until the on-chip pll has locked. the input rstin provides an internal pullup device equalling a resistor of 50 k w to 250 k w (the minimum reset time must be determined by the lowest value). simply connecting an external capacitor is sufficient for an automatic power-on reset (see b ) in figure 20-1 ). rstin may also be connected to the output of other logic gates (see a ) in figure 20-1 ). see also bidirectional reset on page 20-4 in this case. note: a power-on reset requires an active time of two reset sequences (1036 cpu clock cycles) after a stable clock signal is available (about 10 50 ms, depending on the oscillator frequency, to allow the on-chip oscillator to stabilize).
c167cs derivatives system reset users manual 20-3 v2.0, 2000-07 software reset the reset sequence can be triggered at any time via the protected instruction srst (software reset). this instruction can be executed deliberately within a program, e.g. to leave bootstrap loader mode, or upon a hardware trap that reveals a system failure. note: a software reset only latches the configuration of the bus interface (salsel, cssel, wrc, bustyp) from port0 in case of an external reset. if bidirectional reset is enabled, a software reset is executed like a long hardware reset. watchdog timer reset when the watchdog timer is not disabled during the initialization or serviced regularly during program execution it will overflow and trigger the reset sequence. other than hardware and software reset the watchdog reset completes a running external bus cycle if this bus cycle either does not use ready at all, or if ready is sampled active (low) after the programmed waitstates. when ready is sampled inactive (high) after the programmed waitstates the running external bus cycle is aborted. then the internal reset sequence is started. note: a watchdog reset only latches the configuration of the bus interface (salsel, cssel, wrc, bustyp) from port0 in case of an external reset. if bidirectional reset is enabled a watchdog timer reset is executed like a long hardware reset. the watchdog reset cannot occur while the c167cs is in bootstrap loader mode!
c167cs derivatives system reset users manual 20-4 v2.0, 2000-07 bidirectional reset in a special mode (bidirectional reset) the c167css line rstin (normally an input) may be driven active by the chip logic e.g. in order to support external equipment which is required for startup (e.g. flash memory). figure 20-2 bidirectional reset operation bidirectional reset reflects internal reset sources (software, watchdog) also to the rstin pin and converts short hardware reset pulses to a minimum duration of the internal reset sequence. bidirectional reset is enabled by setting bit bdrsten in register syscon and changes rstin from a pure input to an open drain io line. when an internal reset is triggered by the srst instruction or by a watchdog timer overflow or a low level is applied to the rstin line, an internal driver pulls it low for the duration of the internal reset sequence. after that it is released and is then controlled by the external circuitry alone. the bidirectional reset function is useful in applications where external devices require a defined reset signal but cannot be connected to the c167css rstout signal, e.g. an external flash memory which must come out of reset and deliver code well before rstout can be deactivated via einit. the following behavior differences must be observed when using the bidirectional reset feature in an application: ? bit bdrsten in register syscon cannot be changed after einit. ? after a reset bit bdrsten is cleared. ? the reset indication flags always indicate a long hardware reset. ? the port0 configuration is treated like on a hardware reset. especially the bootstrap loader may be activated when p0l.4 or rd is low. ?pin rstin may only be connected to external reset devices with an open drain output driver. ? a short hardware reset is extended to the duration of the internal reset sequence. mcs04403 rstin & internal circuitry reset sequence active bdrsten = '1'
c167cs derivatives system reset users manual 20-5 v2.0, 2000-07 20.2 status after reset after a reset is completed most units of the c167cs enter a well-defined default status. this ensures repeatable start conditions and avoids spurious activities after reset. watchdog timer operation after reset the watchdog timer starts running after the internal reset has completed. it will be clocked with the internal system clock divided by 2 ( f cpu / 2), and its default reload value is 00 h , so a watchdog timer overflow will occur 131,072 cpu clock cycles (2 2 16 ) after completion of the internal reset, unless it is disabled, serviced or reprogrammed meanwhile. when the system reset was caused by a watchdog timer overflow, the wdtr (watchdog timer reset indication) flag in register wdtcon will be set to 1. this indicates the cause of the internal reset to the software initialization routine. wdtr is reset to 0 by an external hardware reset, by servicing the watchdog timer or after einit. after the internal reset has completed, the operation of the watchdog timer can be disabled by the diswdt (disable watchdog timer) instruction. this instruction has been implemented as a protected instruction. for further security, its execution is only enabled in the time period after a reset until either the srvwdt (service watchdog timer) or the einit instruction has been executed. thereafter the diswdt instruction will have no effect. reset values for the c167cs registers during the reset sequence the registers of the c167cs are preset with a default value. most sfrs, including system registers and peripheral control and data registers, are cleared to zero, so all peripherals and the interrupt system are off or idle after reset. a few exceptions to this rule provide a first pre-initialization, which is either fixed or controlled by input pins. dpp1: 0001 h (points to data page 1) dpp2: 0002 h (points to data page 2) dpp3: 0003 h (points to data page 3) cp: fc00 h stkun: fc00 h stkov: fa00 h sp: fc00 h wdtcon: 00xx h (value depends on the reset source) s0rbuf: xx h (undefined) sscrb: xxxx h (undefined) syscon: 0xx0 h (set according to reset configuration) buscon0: 0xx0 h (set according to reset configuration) rp0h: xx h (reset levels of p0h) ones: ffff h (fixed value)
c167cs derivatives system reset users manual 20-6 v2.0, 2000-07 the c167css pins after reset after the reset sequence the different groups of pins of the c167cs are activated in different ways depending on their function. bus and control signals are activated immediately after the reset sequence according to the configuration latched from port0, so either external accesses can takes place or the external control signals are inactive. the general purpose io pins remain in input mode (high impedance) until reprogrammed via software (see figure 20-3 ). the rstout pin remains active (low) until the end of the initialization routine (see description). figure 20-3 reset input and output signals delayed until the end of the internal reset condition. current bus cycle is completed or aborted. activation of the io pins is controlled by software. execution of the einit instruction. when the internal reset condition is extended by rstin, the activation of the output signals is switches asinchronously with rstin, sinchronously upon software or watchdog reset. the reset condition ends here. the c 167cr starts program execution. the shaded area designates the internal reset sequence, which starts after synchronization of rstin. rstin internal reset condition 6) initialization 3) mcs02258 rd, wr rstout io ale bus rstin internal reset condition 6) 1) 2) 2) initialization 3) 5) 4) 8) 7) a short hardware reset is extended until the end of the reset sequence in bidirectional reset mode. a software or wdt reset activates the rstin line in bidirectional reset mode. 8) 7) 6) 3) 2) 5) 4) 1)
c167cs derivatives system reset users manual 20-7 v2.0, 2000-07 ports and external bus configuration during reset during the internal reset sequence all of the c167cs s port pins are configured as inputs by clearing the associated direction registers, and their pin drivers are switched to the high impedance state. this ensures that the c167cs and external devices will not try to drive the same pin to different levels. pin ale is held low through an internal pulldown, and pins rd , wr and ready are held high through internal pullups. also the pins that can be configured for cs output will be pulled high. the registers syscon and buscon0 are initialized according to the configuration selected via port0. when an external start is selected (pin ea = 0): ? the bus type field (btyp) in register buscon0 is initialized according to p0l.7 and p0l.6 ? bit busact0 in register buscon0 is set to 1 ? bit alectl0 in register buscon0 is set to 1 ? bit romen in register syscon will be cleared to 0 ? bit bytdis in register syscon is set according to the data bus width (set if 8-bit) ? bit wrcfg in register syscon is set according to pin p0h.0 (wrc) when an internal start is selected (pin ea = 1): ? register buscon0 is initialized to 00c0 h ? bit romen in register syscon will be set to 1 ? bit bytdis in register syscon is set, i.e. bhe /wrh is disabled ? bit wrcfg in register syscon is set according to pin p0h.0 (wrc) the other bits of register buscon0, and the other buscon registers are cleared. this default initialization selects the slowest possible external accesses using the configured bus type. when the internal reset has completed, the configuration of port0, port1, port 4, port 6, and of the bhe signal (high byte enable, alternate function of p3.12) depends on the bus type which was selected during reset. when any of the external bus modes was selected during reset, port0 will operate in the selected bus mode. port 4 will output the selected number of segment address lines (all zero after reset). port 6 will drive the selected number of cs lines (cs0 will be 0, while the other active cs lines will be 1). when no memory accesses above 64 k are to be performed, segmentation may be disabled. when the on-chip bootstrap loader was activated during reset, pin txd0 (alternate port function) will be switched to output mode after the reception of the zero byte. all other pins remain in the high-impedance state until they are changed by software or peripheral operation.
c167cs derivatives system reset users manual 20-8 v2.0, 2000-07 reset output pin the rstout pin is dedicated to generate a reset signal for the system components besides the controller itself. rstout will be driven active (low) at the begin of any reset sequence (triggered by hardware, the srst instruction or a watchdog timer overflow). rstout stays active (low) beyond the end of the internal reset sequence until the protected einit (end of initialization) instruction is executed (see figure 20-3 ). this allows the complete configuration of the controller including its on-chip peripheral units before releasing the reset signal for the external peripherals of the system. note: rstout will float during emulation mode or adapt mode. the internal ram after reset the contents of the internal ram are not affected by a system reset. however, after a power-on reset, the contents of the internal ram are undefined. this implies that the gprs (r15 r0) and the pec source and destination pointers (srcp7 srcp0, dstp7 dstp0) which are mapped into the internal ram are also unchanged after a warm reset, software reset or watchdog reset, but are undefined after a power-on reset. the extension ram (xram) after reset the contents of the on-chip extension ram are not affected by a system reset. however, after a power-on reset, the contents of the xram are undefined. operation after reset after the internal reset condition is removed the c167cs fetches the first instruction from the program memory (location 000000 h for a standard start). as a rule, this first location holds a branch instruction to the actual initialization routine that may be located anywhere in the address space. note: when the bootstrap loader mode was activated during a hardware reset the c167cs does not fetch instructions from the program memory. the standard bootstrap loader expects data via serial interface asc0.
c167cs derivatives system reset users manual 20-9 v2.0, 2000-07 20.3 application-specific initialization routine after a reset the modules of the c167cs must be initialized to enable their operation on a given application. this initialization depends on the task the c167cs is to fulfill in that application and on some system properties like operating frequency, connected external circuitry, etc. the following initializations should typically be done, before the c167cs is prepared to run the actual application software: memory areas the external bus interface can be reconfigured after an external reset because register buscon0 is initialized to the slowest possible bus cycle configuration. the programmable address windows can be enabled in order to adapt the bus cycle characteristics to different memory areas or peripherals. also after a single-chip mode reset the external bus interface can be enabled and configured. the internal program memory (if available) can be enabled and mapped after an external reset in order to use the on-chip resources. after a single-chip mode reset the internal program memory can be remapped or disabled at all in order to utilize external memory (partly or completely). programmable program memory can be programmed, e.g. with data received over a serial link. note: initial flash or otp programming will rather be done in bootstrap loader mode. system stack the default setup for the system stack (size, stackpointer, upper and lower limit registers) can be adjusted to application-specific values. after reset, registers sp and stkun contain the same reset value 00fc00 h , while register stkov contains 00fa00 h . with the default reset initialization, 256 words of system stack are available, where the system stack selected by the sp grows downwards from 00fbfe h . note: the interrupt system, which is disabled upon completion of the internal reset, should remain disabled until the sp is initialized. traps (incl. nmi ) may occur, even though the interrupt system is still disabled. register bank the location of a register bank is defined by the context pointer (cp) and can be adjusted to an application-specific bank before the general purpose registers (gprs) are used. after reset, register cp contains the value 00fc00 h , i.e. the register bank selected by the cp grows upwards from 00fc00 h .
c167cs derivatives system reset users manual 20-10 v2.0, 2000-07 on-chip ram based on the application, the user may wish to initialize portions of the internal writable memory (iram/xram) before normal program operation. once the register bank has been selected by programming the cp register, the desired portions of the internal memory can easily be initialized via indirect addressing. interrupt system after reset the individual interrupt nodes and the global interrupt system are disabled. in order to enable interrupt requests the nodes must be assigned to their respective interrupt priority levels and be enabled. the vector locations must receive pointers to the respective exception handlers. the interrupt system must globally be enabled by setting bit ien in register psw. care must be taken not to enable the interrupt system before the initialization is complete in order to avoid e.g. the corruption of internal memory locations by stack operations using an uninitialized stack pointer. watchdog timer after reset the watchdog timer is active and is counting its default period. if the watchdog timer shall remain active the desired period should be programmed by selecting the appropriate prescaler value and reload value. otherwise the watchdog timer must be disabled before einit. ports generally all ports of the c167cs are switched to input after reset. some pins may be automatically controlled, e.g. bus interface pins for an external start, txd in boot mode, etc. pins that shall be used for general purpose io must be initialized via software. the required mode (input/output, open drain/push pull, input threshold, etc.) depends on the intended function for a given pin. peripherals after reset the c167css on-chip peripheral modules enter a defined default state (see respective peripheral description) where it is disabled from operation. in order to use a certain peripheral it must be initialized according to its intended operation in the application. this includes selecting the operating mode (e.g. counter/timer), operating parameters (e.g. baudrate), enabling interface pins (if required), assigning interrupt nodes to the respective priority levels, etc. after these standard initialization also application-specific actions may be required like asserting certain levels to output pins, sending codes via interfaces, latching input levels, etc.
c167cs derivatives system reset users manual 20-11 v2.0, 2000-07 termination of initialization the software initialization routine should be terminated with the einit instruction. this instruction has been implemented as a protected instruction. the execution of the einit instruction: ? disables the action of the diswdt instruction, ? disables write accesses to reg. syscon (all configurations regarding reg. syscon (enable clkout, stacksize, etc.) must be selected before the execution of einit), ? disables write accesses to registers syscon2 and syscon3 (further write accesses to syscon2 and syscon3 can be executed only using a special unlock mechanism), ? clears the reset source detection bits in register wdtcon, ? causes the rstout pin to go high (this signal can be used to indicate the end of the initialization routine and the proper operation of the microcontroller to external hardware).
c167cs derivatives system reset users manual 20-12 v2.0, 2000-07 20.4 system startup configuration although most of the programmable features of the c167cs are selected by software either during the initialization phase or repeatedly during program execution, there are some features that must be selected earlier, because they are used for the first access of the program execution (e.g. internal or external start selected via ea ). these configurations are accomplished by latching the logic levels at a number of pins at the end of the internal reset sequence. during reset internal pullup/pulldown devices are active on those lines. they ensure inactive/default levels at pins which are not driven externally. external pulldown/pullup devices may override the default levels in order to select a specific configuration. many configurations can therefore be coded with a minimum of external circuitry. note: the load on those pins that shall be latched for configuration must be small enough for the internal pullup/pulldown device to sustain the default level, or external pullup/pulldown devices must ensure this level. those pins whose default level shall be overridden must be pulled low/high externally. make sure that the valid target levels are reached until the end of the reset sequence. there is a specific application note to illustrate this.
c167cs derivatives system reset users manual 20-13 v2.0, 2000-07 20.4.1 system startup configuration upon an external reset for an external reset (ea = 0) the startup configuration uses the pins of port0 and pin rd . the value on the upper byte of port0 (p0h) is latched into register rp0h upon reset, the value on the lower byte (p0l) directly influences the buscon0 register (bus mode) or the internal control logic of the c167cs. figure 20-4 port0 configuration during reset the pins that control the operation of the internal control logic, the clock configuration, and the reserved pins are evaluated only during a hardware triggered reset sequence. the pins that influence the configuration of the c167cs are evaluated during any reset sequence, i.e. also during software and watchdog timer triggered resets. the configuration via p0h is latched in register rp0h for subsequent evaluation by software. register rp0h is described in chapter 9 . the following describes the different selections that are offered for reset configuration. the default modes refer to pins at high level, i.e. without external pulldown devices connected. please also consider the note above. mca04484 emu adp smod bustyp wrc calsel clkcfg cssel clock generator port 4 logic port 6 logic internal control logic (only on hardware reset) l.0 l.1 l.2 l.3 l.4 l.5 l.6 l.7 h.0 h.1 h.2 h.3 h.4 h.5 h.6 h.7 syscon buscon0 pr0h rd
c167cs derivatives system reset users manual 20-14 v2.0, 2000-07 emulation mode pin p0l.0 (emu) selects the emulation mode, when latched low at the end of reset. this mode is used for special emulation and testing purposes and is of minor use for standard c167cs applications, so p0l.0 should be held high. emulation mode provides access to integrated xbus peripherals via the external bus interface pins (direction reversed) of the c167cs. the cpu and the generic peripherals are disabled, all modules connected via the xbus are active. default: emulation mode is off. note: in emulation mode pin p0.15 (p0h.7) is inverted, i.e. the configuration 111 would select direct drive in emulation mode. emulation mode can only be activated upon an external reset (ea = 0). pin p0l.0 is not evaluated upon a single-chip reset (ea = 1). table 20-1 emulation mode summary pin(s) function notes port 4, port1 address input the segment address lines configured at reset must be driven externally port0 data input/output C rd , wr control signal input C ale unused input hold low clkout cpu clock output enabled automatically rstout reset input drive externally for an xbus peripheral reset rstin reset input standard reset for complete device port 6 interrupt output sends xbus peripheral interrupt request e.g. to the emulation system
c167cs derivatives system reset users manual 20-15 v2.0, 2000-07 adapt mode pin p0l.1 (adp) selects the adapt mode, when latched low at the end of reset. in this mode the c167cs goes into a passive state, which is similar to its state during reset. the pins of the c167cs float to tristate or are deactivated via internal pullup/pulldown devices, as described for the reset state. in addition also the rstout pin floats to tristate rather than be driven low. the on-chip oscillator and the realtime clock are disabled. this mode allows switching a c167cs that is mounted to a board virtually off, so an emulator may control the boards circuitry, even though the original c167cs remains in its place. the original c167cs also may resume to control the board after a reset sequence with p0l.1 high. please note that adapt mode overrides any other configuration via port0. default: adapt mode is off. note: when xtal1 is fed by an external clock generator (while xtal2 is left open), this clock signal may also be used to drive the emulator device. however, if a crystal is used, the emulator devices oscillator can use this crystal only, if at least xtal2 of the original device is disconnected from the circuitry (the output xtal2 will be driven high in adapt mode). adapt mode can only be activated upon an external reset (ea = 0). pin p0l.1 is not evaluated upon a single-chip reset (ea = 1).
c167cs derivatives system reset users manual 20-16 v2.0, 2000-07 special operation modes pins p0l.5 to p0l.2 (smod) select special operation modes of the c167cs during reset (see table 20-2 ). make sure to only select valid configurations in order to ensure proper operation of the c167cs. the on-chip bootstrap loader allows moving the start code into the internal ram of the c167cs via the serial interface asc0. the c167cs will remain in bootstrap loader mode until a hardware reset not selecting bsl mode or a software reset. default: the c167cs starts fetching code from location 000000 h , the bootstrap loader is off. table 20-2 definition of special modes for reset configuration p0.5-2 (p0l.5-2) special mode notes 1111 normal start default configuration. begin of execution as defined via pin ea . 1110 reserved do not select this configuration! 1101 reserved do not select this configuration! 1100 reserved do not select this configuration! 1011 standard bootstrap loader load an initial boot routine of 32 bytes via interface asc0. 1010 reserved do not select this configuration! 1001 alternate boot operation not yet defined. do not use! 1000 reserved do not select this configuration! 0111 no emulation mode: alternate start operation not yet defined. do not use! emulation mode: external host mode (ehm) programming mode for flash memory via external host. 0110 reserved do not select this configuration! 0101 reserved do not select this configuration! 0100 reserved do not select this configuration! 0 0 x x reserved do not select this configuration!
c167cs derivatives system reset users manual 20-17 v2.0, 2000-07 external bus type pins p0l.7 and p0l.6 (bustyp) select the external bus type during reset, if an external start is selected via pin ea . this allows the configuration of the external bus interface of the c167cs even for the first code fetch after reset. the two bits are copied into bit field btyp of register buscon0. p0l.7 controls the data bus width, while p0l.6 controls the address output (multiplexed or demultiplexed). this bit field may be changed via software after reset, if required. port0 and port1 are automatically switched to the selected bus mode. in multiplexed bus modes port0 drives both the 16-bit intra-segment address and the output data, while port1 remains in high impedance state as long as no demultiplexed bus is selected via one of the buscon registers. in demultiplexed bus modes port1 drives the 16-bit intra-segment address, while port0 or p0l (according to the selected data bus width) drives the output data. for a 16-bit data bus bhe is automatically enabled, for an 8-bit data bus bhe is disabled via bit bytdis in register syscon. default: 16-bit data bus with multiplexed addresses. note: if an internal start is selected via pin ea , these two pins are disregarded and bit field btyp of register buscon0 is cleared. write configuration pin p0h.0 (wrc) selects the initial operation of the control pins wr and bhe during reset. when high, this pin selects the standard function, i.e. wr control and bhe . when low, it selects the alternate configuration, i.e. wrh and wrl . thus even the first access after a reset can go to a memory controlled via wrh and wrl . this bit is latched in register rp0h and its inverted value is copied into bit wrcfg in register syscon. default: standard function (wr control and bhe ). table 20-3 configuration of external bus type p0l.7-6 (btyp) encoding external data bus width external address bus mode 0 0 8-bit data demultiplexed addresses 0 1 8-bit data multiplexed addresses 1 0 16-bit data demultiplexed addresses 1 1 16-bit data multiplexed addresses
c167cs derivatives system reset users manual 20-18 v2.0, 2000-07 chip select lines pins p0h.2 and p0h.1 (cssel) define the number of active chip select signals during reset. this allows the selection which pins of port 6 drive external cs signals and which are used for general purpose io. the two bits are latched in register rp0h. default: all 5 chip select lines active (cs4 cs0 ). note: the selected number of cs signals can be changed via software after reset (see section 20.4.2 ). segment address lines pins p0h.4 and p0h.3 (salsel) define the number of active segment address lines during reset. this allows the selection which pins of port 4 drive address lines and which are used for general purpose io. the two bits are latched in register rp0h. depending on the system architecture the required address space is chosen and accessible right from the start, so the initialization routine can directly access all locations without prior programming. the required pins of port 4 are automatically switched to address output mode. even if not all segment address lines are enabled on port 4, the c167cs internally uses its complete 24-bit addressing mechanism. this allows the restriction of the width of the effective address bus, while still deriving cs signals from the complete addresses. default: 2-bit segment address (a17 a16) allowing access to 256 kbyte. note: the selected number of segment address lines can be changed via software after reset (see section 20.4.2 ). table 20-4 configuration of chip select lines p0h.2-1 (cssel) chip select lines note 1 1 five: cs4 cs0 default without pull-downs 1 0 none C 0 1 two: cs1 cs0 C 0 0 three:cs2 cs0 C table 20-5 configuration of segment address lines p0h.4-3 (salsel) segment address lines directly accessible a. space 1 1 two: a17 a16 256 kbyte (default without pull- downs) 1 0 eight: a23 a16 16 mbyte (maximum) 0 1 none 64 kbyte (minimum) 0 0 four: a19 a16 1 mbyte
c167cs derivatives system reset users manual 20-19 v2.0, 2000-07 clock generation control pins p0h.7, p0h.6 and p0h.5 (clkcfg) select the basic clock generation mode during reset. the oscillator clock either directly feeds the cpu and peripherals (direct drive), it is divided by 2 or it is fed to the on-chip pll which then provides the cpu clock signal (selectable multiple of the oscillator frequency, i.e. the input frequency). these bits are latched in register rp0h. default: on-chip pll is active with a factor of 1:4. watch the different requirements for frequency and duty cycle of the oscillator input clock for the possible selections. oscillator watchdog control the on-chip oscillator watchdog (owd) may be disabled via hardware by (externally) pulling the rd line low upon a reset, similar to the standard reset configuration via port0. at the end of any reset bit owddis in register syscon reflects the inverted level of pin rd at that time. the software may again enable the oscillator watchdog by clearing bit owddis before the execution of einit. note: if direct drive or prescaler operation is selected as basic clock generation mode (see above) the pll is switched off whenever bit owddis is set (via software or via hardware configuration). table 20-6 c167cs clock generation modes (p0h.7-5) (clkcfg) cpu frequency f cpu = f osc f external clock input rang 1) 1) the external clock input range refers to a cpu clock range of 10 33 mhz. notes 1 1 1 f osc 4 2.5 to 8.25 mhz default configuration 1 1 0 f osc 3 3.33 to 11 mhz C 10 1 f osc 2 5 to 16.5 mhz C 1 0 0 f osc 5 2 to 6.6 mhz C 0 1 1 f osc 1 1 to 33 mhz direct drive 2) 2) the maximum frequency depends on the duty cycle of the external clock signal. in emulation mode pin p0.15 (p0h.7) is inverted, i.e. the configuration 111 would select direct drive in emulation mode. 0 1 0 f osc 1.5 6.66 to 22 mhz C 0 0 1 f osc / 2 2 to 66 mhz cpu clock via prescaler 0 0 0 f osc 2.5 4 to 13.2 mhz C
c167cs derivatives system reset users manual 20-20 v2.0, 2000-07 20.4.2 system startup configuration upon a single-chip mode reset for a single-chip mode reset (indicated by ea = 1) the configuration via port0 is replaced by a fixed configuration value. in this case port0 needs no external circuitry (pullups/pulldowns) and also the internal configuration pullups are not activated. the necessary startup modes are configured via pins rd and ale. this fixed default configuration is activated after each long hardware reset and selects a safe worst-case configuration. the initialization software can then modify these parameters and select the intended configuration for a given application. table 20-7 lists the respective default configuration values which are selected, and the bitfields that permit software modification. note: single-chip mode reset cannot be selected on romless devices. the attempt to read the first instruction after reset will fail in such a case. table 20-7 default configuration for single-chip mode reset configuration parameter default values (rp0h = xx2d h ) external config. 1) 1) refers to the configuration pins which are replaced by the default values. software access 2) 2) software can modify the default values via these bitfields. clkcfg: generation mode of basic clock 001 = prescaler operation, i.e. f cpu = f osc / 2 p0.15-13 rstcon.15-13 salsel: number of active segment address lines 01 = no segment address lines p0.12-11 rstcon.12-11 cssel: number of active cs lines 10 = no chip select lines p0.10-9 rstcon.10-9 wrc: write signal encoding rp0h.0 = 1, syscon.wrcfg = 0, i.e. wr and bhe p0.8 syscon.wrcfg btyp: default bustype (buscon0) buscon0.btyp = 11 i.e. 16-bit mux bus p0.7-6 buscon0.btyp smod: special modes (start/boot modes) startup modes selected via pins rd and ale p0.5-2 C adp: adapt mode not possible p0.1 C emu: emulation mode not possible p0.0 C owd disable syscon.owddis = 0 i.e. owd is active rd syscon.owddis
c167cs derivatives system reset users manual 20-21 v2.0, 2000-07 single-chip startup modes the startup mode (operation after reset) of the c167cs can be configured during reset. in single-chip mode this configuration is selected via pins rd and ale. pin rd selects start or boot mode (instead of owd control), pin ale selects one of two alternatives in each case. table 20-8 startup mode configuration in single-chip reset mode rd ale startup mode notes 1 0 standard start execution starts at user memory location 000000 h . 1 1 alternate start operation not yet defined. do not use! 0 0 standard bootstrap loader load 32 bytes via asc0. 0 1 alternate boot mode operation not yet defined. do not use!
c167cs derivatives system reset users manual 20-22 v2.0, 2000-07 20.5 system configuration via software the system configuration which is selected via hardware after reset (latched pin levels or default value) can be changed via software by executing a specific code sequence. the respective control bits are located within registers syscon, busconx, and rstcon. register syscon can only be modified before the execution of instruction einit, while registers busconx and rstcon (using the specific sequence) can be modified repeatedly at any time. the clock generation mode (clkcfg), the segment address width (salsel), and the number of chip select lines (cssel) are controlled by register rp0h. rp0h is initialized according to the selected reset mode (pins or default). the respective configuration bitfields can be copied from register rstcon upon entering slow down divider mode if enabled by bit sue = 1. the following steps must be taken to change the current configuration (see also sw example): ? write intended configuration value to rstcon ? enter sdd mode ? return to basic clock mode change_clock_configuration: ;"rstcon" is a mem address, no sfr mov r15, #11100001xxxxxxxxb ;load a gpr with the target value mov rstcon, r15 ;enable update with pll factor 4 extr #2 ;esfr-access to syscon2 mov syscon2, #0100h ;sdd mode, pll on, factor 1 ;rstcon.15-9 is copied to rp0h.15-9 mov syscon2, #0400h ;switch to basic clock mode ;system will run on pll (factor 4).. ;..after pll has locked note: this software example assumes execution before einit. otherwise the unlock sequence has to be executed prior to each access to rstcon/syscon2. entering sdd mode temporarily ensures a correct clock signal synchronization in cases where the clock generation mode (e.g. pll factor) is changed. if the target basic clock generation mode uses the pll, the c167cs will run in direct-drive mode until the pll has locked. software modification of system configuration values is protected by the following features: ? syscon is locked after einit ? rstcon requires the unlock sequence after einit ? copying rstcon to rp0h must be explicitly enabled by setting bit sue
c167cs derivatives system reset users manual 20-23 v2.0, 2000-07 rstcon reset control register mem (f1e0 h /--) reset value: 00xx h 1514131211109876543210 clkcfg salsel cssel sue ------rstlen rw rw rw rw - - - - - - rw bit function rstlen reset length control (duration of the next reset sequence to occur) 1) 00: 1024 tcl: standard duration, corresponds to all other derivatives without control function 01: 2048 tcl: extended duration, may be useful e.g. to provide additional settling for external configuration signals at high cpu clock frequencies 10: reserved 11: reserved sue software update enable 0: configuration cannot be changed via software 1: software update of configuration is enabled cssel chip select line selection (number of active cs outputs) 00: 3 cs lines: cs2 cs0 01: 2 cs lines: cs1 cs0 10: no cs lines at all 11: all cs lines: csx cs0 salsel segment address line selection (number of active seg-addr. outputs) 00: 4-bit segment address: a19 a16 01: no segment address lines at all 10: full segment address: axx a16 11: 2-bit segment address: a17 a16 clkcfg clock generation mode configuration these pins define the clock generation mode, i.e. the mechanism how the the internal cpu clock is generated from the externally applied (xtal1) input clock. 000: pll ( f 2.5) 100: pll ( f 5) 001: prescaler ( f / 2) 101: pll ( f 2) 010: pll ( f 1.5) 110: pll ( f 3) 011: direct drive ( f = f ) 111: pll ( f 4) 1) rstlen is always valid for the next reset sequence. an initial power up reset, however, is expected to last considerably longer than any configurable reset sequence.
c167cs derivatives system reset users manual 20-24 v2.0, 2000-07 note: rstcon is write protected after the execution of einit unless it is released via the unlock sequence (see section 21.7 ). rstcon can only be accessed via its long (mem) address.
c167cs derivatives power management users manual 21-1 v2.0, 2000-07 21 power management for an increasing number of microcontroller based systems it is an important objective to reduce the power consumption of the system as much as possible. a contradictory objective is, however, to reach a certain level of system performance. besides optimization of design and technology a microcontrollers power consumption can generally be reduced by lowering its operating frequency and/or by reducing the circuitry that is clocked. the architecture of the c167cs provides three major means of reducing its power consumption (see figure 21-1 ) under software control: ? reduction of the cpu frequency for slow down operation (flexible clock generation management) ? selection of the active peripheral modules (flexible peripheral management) ? special operating modes to deactivate cpu, ports, and control logic (idle, sleep, power down) this enables the application (i.e. the programmer) to choose the optimum constellation for each operating condition, so the power consumption can be adapted to conditions like maximum performance, partial performance, intermittend operation or standby. figure 21-1 power reduction possibilities mca04476 active idle power down f cpu power idle no. of act. peripherals active
c167cs derivatives power management users manual 21-2 v2.0, 2000-07 intermittend operation (i.e. alternating phases of high performance and power saving) is supported by the cyclic interrupt generation mode of the on-chip rtc (real time clock). these three means described above can be applied independent from each other and thus provide a maximum of flexibility for each application. for the basic power reduction modes (idle, power down) there are dedicated instructions, while special registers control sleep mode (syscon1), clock generation (syscon2), and peripheral management (syscon3). three different general power reduction modes with different levels of power reduction have been implemented in the c167cs, which may be entered under software control: in idle mode the cpu is stopped, while the (enabled) peripherals continue their operation. idle mode can be terminated by any reset or interrupt request. in sleep mode both the cpu and the peripherals are stopped. the real time clock and its selected oscillator may optionally be kept running. sleep mode can be terminated by any reset or interrupt request (mainly hardware requests, stopped peripherals cannot generate interrupt requests). in power down mode both the cpu and the peripherals are stopped. the real time clock and its selected oscillator may optionally be kept running. power down mode can only be terminated by a hardware reset. note: all external bus actions are completed before idle or power down mode is entered. however, idle or power down mode is not entered if ready is enabled, but has not been activated (driven low) during the last bus access. in addition the power management selects the current cpu frequency and controls which peripherals are active. during slow down operation the basic clock generation path is bypassed and the cpu clock is generated via the programmable slow down divider (sdd) from the selected oscillator clock signal. peripheral management disables and enables the on-chip peripheral modules independently, reducing the amount of clocked circuitry including the respective clock drivers.
c167cs derivatives power management users manual 21-3 v2.0, 2000-07 21.1 idle mode the power consumption of the c167cs microcontroller can be decreased by entering idle mode. in this mode all enabled peripherals, including the watchdog timer, continue to operate normally, only the cpu operation is halted and the on-chip memory modules are disabled. note: peripherals that have been disabled via software also remain disabled after entering idle mode, of course. idle mode is entered after the idle instruction has been executed and the instruction before the idle instruction has been completed (bitfield sleepcon in register syscon1 must be 00 b ). to prevent unintentional entry into idle mode, the idle instruction has been implemented as a protected 32-bit instruction. idle mode is terminated by interrupt requests from any enabled interrupt source whose individual interrupt enable flag was set before the idle mode was entered, regardless of bit ien. for a request selected for cpu interrupt service the associated interrupt service routine is entered if the priority level of the requesting source is higher than the current cpu priority and the interrupt system is globally enabled. after the reti (return from interrupt) instruction of the interrupt service routine is executed the cpu continues executing the program with the instruction following the idle instruction. otherwise, if the interrupt request cannot be serviced because of a too low priority or a globally disabled interrupt system the cpu immediately resumes normal program execution with the instruction following the idle instruction. for a request which was programmed for pec service a pec data transfer is performed if the priority level of this request is higher than the current cpu priority and the interrupt system is globally enabled. after the pec data transfer has been completed the cpu remains in idle mode. otherwise, if the pec request cannot be serviced because of a too low priority or a globally disabled interrupt system the cpu does not remain in idle mode but continues program execution with the instruction following the idle instruction.
c167cs derivatives power management users manual 21-4 v2.0, 2000-07 figure 21-2 transitions between idle mode and active mode idle mode can also be terminated by a non-maskable interrupt, i.e. a high to low transition on the nmi pin. after idle mode has been terminated by an interrupt or nmi request, the interrupt system performs a round of prioritization to determine the highest priority request. in the case of an nmi request, the nmi trap will always be entered. any interrupt request whose individual interrupt enable flag was set before idle mode was entered will terminate idle mode regardless of the current cpu priority. the cpu will not go back into idle mode when a cpu interrupt request is detected, even when the interrupt was not serviced because of a higher cpu priority or a globally disabled interrupt system (ien = 0). the cpu will only go back into idle mode when the interrupt system is globally enabled (ien = 1) and a pec service on a priority level higher than the current cpu level is requested and executed. note: an interrupt request which is individually enabled and assigned to priority level 0 will terminate idle mode. the associated interrupt vector will not be accessed, however. the watchdog timer may be used to monitor the idle mode: an internal reset will be generated if no interrupt or nmi request occurs before the watchdog timer overflows. to prevent the watchdog timer from overflowing during idle mode it must be programmed to a reasonable time interval before idle mode is entered. mca04407 idle mode active mode denied accepted cpu interrupt request idle instruction denied pec request executed pec request
c167cs derivatives power management users manual 21-5 v2.0, 2000-07 21.2 sleep mode to further reduce the power consumption the microcontroller can be switched to sleep mode. clocking of all internal blocks is stopped (rtc and selected oscillator optionally), the contents of the internal ram, however, are preserved through the voltage supplied via the v dd pins. the watchdog timer is stopped in sleep mode. sleep mode is selected via bitfield sleepcon in register syscon1 and is entered after the idle instruction has been executed and the instruction before the idle instruction has been completed. sleep mode is terminated by interrupt requests from any enabled interrupt source whose individual interrupt enable flag was set before the idle mode was entered, regardless of bit ien. mainly these are external interrupts and the rtc (if running). note: the receive lines of serial interfaces may be internally routed to external interrupt inputs (see exisel). all peripherals except for the rtc are stopped and hence cannot generate an interrupt request. the realtime clock (rtc) can be kept running in sleep mode in order to maintain a valid system time as long as the supply voltage is applied. this enables a system to determine the current time and the duration of the period while it was down (by comparing the current time with a timestamp stored when sleep mode was entered). the supply current in this case remains well below 1 ma. during sleep mode the voltage at the v dd pins can be lowered to 2.7 v while the rtc and its selected oscillator will still keep on running and the contents of the internal ram will still be preserved. when the rtc (and oscillator) is disabled the internal ram is preserved down to a voltage of 2.5 v. note: when the rtc remains active in sleep mode also the oscillator which generates the rtc clock signal will keep on running, of course. if the supply voltage is reduced the specified maximum cpu clock frequency for this case must be respected. for wakeup (input edge recognition and cpu start) the power must be within the specified limits, however. the total power consumption in sleep mode depends on the active circuitry (i.e. rtc on or off) and on the current that flows through the port drivers. individual port drivers can be disabled simply by configuring them for input. the bus interface pins can be separately disabled by releasing the external bus (disable all address windows by clearing the busact bits) and switching the ports to input (if necessary). of course the required software in this case must be executed from internal memory.
c167cs derivatives power management users manual 21-6 v2.0, 2000-07 note: syscon1 is write protected after the execution of einit unless it is released via the unlock sequence (see table 21-6 ). 21.3 power down mode the microcontroller can be switched to power down mode which reduces the power consumption to a minimum. clocking of all internal blocks is stopped (rtc and oscillator optionally), the contents of the internal ram, however, are preserved through the voltage supplied via the v dd pins. the watchdog timer is stopped in power down mode. this mode can only be terminated by an external hardware reset, i.e. by asserting a low level on the rstin pin. this reset will initialize all sfrs and ports to their default state, but will not change the contents of the internal ram. there are two levels of protection against unintentionally entering power down mode. first, the pwrdn (power down) instruction which is used to enter this mode has been implemented as a protected 32-bit instruction. second, this instruction is effective only if the nmi (non maskable interrupt) pin is externally pulled low while the pwrdn instruction is executed. the microcontroller will enter power down mode after the pwrdn instruction has completed. this feature can be used in conjunction with an external power failure signal which pulls the nmi pin low when a power failure is imminent. the microcontroller will enter the nmi trap routine which can save the internal state into ram. after the internal state has been saved, the trap routine may then execute the pwrdn instruction. if the nmi pin is still low at this time, power down mode will be entered, otherwise program execution continues. syscon1 system control reg.1 esfr (f1dc h /ee h ) reset value: 0000 h 1514131211109876543210 -------------- sleep con - - - - - - - - - - - - - - rw bit function sleepcon sleep mode configuration (mode entered upon the idle instruction) 00: normal idle mode 01: sleep mode, with rtc running 10: reserved. 11: sleep mode, with rtc and oscillator stopped
c167cs derivatives power management users manual 21-7 v2.0, 2000-07 the initialization routine (executed upon reset) can check the reset identification flags in register wdtcon to determine whether the controller was initially switched on, or whether it was properly restarted from power down mode. the realtime clock (rtc) can be kept running in power down mode in order to maintain a valid system time as long as the supply voltage is applied. this enables a system to determine the current time and the duration of the period while it was down (by comparing the current time with a timestamp stored when power down mode was entered). the supply current in this case remains well below 1 ma. during power down the voltage at the v dd pins can be lowered to 2.7 v while the rtc and its selected oscillator will still keep on running and the contents of the internal ram will still be preserved. when the rtc (and oscillator) is disabled the internal ram is preserved down to a voltage of 2.5 v. note: when the rtc remains active in power down mode also the oscillator which generates the rtc clock signal will keep on running, of course. if the supply voltage is reduced the specified maximum cpu clock frequency for this case must be respected. the total power consumption in power down mode depends on the active circuitry (i.e. rtc on or off) and on the current that flows through the port drivers. to minimize the consumed current the rtc and/or all pin drivers can be disabled (pins switched to tristate) via a central control bitfield in register syscon2. if an application requires one or more port drivers to remain active even in power down mode also individual port drivers can be disabled simply by configuring them for input. the bus interface pins can be separately disabled by releasing the external bus (disable all address windows by clearing the busact bits) and switching the ports to input (if necessary). of course the required software in this case must be executed from internal memory.
c167cs derivatives power management users manual 21-8 v2.0, 2000-07 21.3.1 status of output pins during power reduction modes during idle mode the cpu clocks are turned off, while all peripherals continue their operation in the normal way. therefore all ports pins, which are configured as general purpose output pins, output the last data value which was written to their port output latches. if the alternate output function of a port pin is used by a peripheral, the state of the pin is determined by the operation of the peripheral. port pins which are used for bus control functions go into that state which represents the inactive state of the respective function (e.g. wr ), or to a defined state which is based on the last bus access (e.g. bhe ). port pins which are used as external address/data bus hold the address/data which was output during the last external memory access before entry into idle mode under the following conditions: p0h outputs the high byte of the last address if a multiplexed bus mode with 8-bit data bus is used, otherwise p0h is floating. p0l is always floating in idle mode. port1 outputs the lower 16 bits of the last address if a demultiplexed bus mode is used, otherwise the output pins of port1 represent the port latch data. port 4 outputs the segment address for the last access on those pins that are selected as segment address lines, otherwise the output pins of port 4 represent the port latch data. during sleep mode the oscillator (except for rtc operation) and the clocks to the cpu and to the peripherals are turned off. like in idle mode, all port pins which are configured as general purpose output pins output the last data value which was written to their port output latches. when the alternate output function of a port pin is used by a peripheral the state of this pin is determined by the last action of the peripheral before the clocks were switched off. during power down mode the oscillator (except for rtc operation) and the clocks to the cpu and to the peripherals are turned off. like in idle mode, all port pins which are configured as general purpose output pins output the last data value which was written to their port output latches. when the alternate output function of a port pin is used by a peripheral the state of this pin is determined by the last action of the peripheral before the clocks were switched off. note: all pin drivers can be switched off by selecting the general port disable function prior to entering power down mode. when the supply voltage is lowered in power down mode the high voltage of output pins will decrease accordingly.
c167cs derivatives power management users manual 21-9 v2.0, 2000-07 table 21-1 state of c167cs output pins during idle and power down mode c167cs output pin(s) external bus enabled no external bus idle mode sleep and power down idle mode sleep and power down clkout active (toggling) high active (toggling) high fout active (toggling) hold (high / low) active (toggling) hold (high / low) ale low low rd , wr high high p0l floating port latch data p0h a15 a8 1) /float port latch data port1 last address 2) /port latch data port latch data port 4 port latch data/last segment port latch data bhe last value port latch data csx last value 3) port latch data rstout high if einit was executed before entering idle or power down mode, low otherwise. other port output pins port latch data/alternate function 1) for multiplexed buses with 8-bit data bus. 2) for demultiplexed buses. 3) the cs signal that corresponds to the last address remains active (low), all other enabled cs signals remain inactive (high). by accessing an on-chip x-periperal prior to entering a power save mode all external cs signals can be deactivated.
c167cs derivatives power management users manual 21-10 v2.0, 2000-07 21.4 slow down operation a separate clock path can be selected for slow down operation bypassing the basic clock path used for standard operation. the programmable slow down divider (sdd) divides the oscillator frequency by a factor of 1 32 which is specified via bitfield clkrel in register syscon2 (factor = +1). when bitfield clkrel is written during sdd operation the reload counter will output one more clock pulse with the old frequency in order to resynchronize internally before generating the new frequency. if direct drive mode is configured clock signal f dd is directly fed to f cpu , if prescaler mode is configured clock signal f dd is additionally divided by 2:1 to generate f cpu (see examples below). figure 21-3 slow down divider operation using e.g. a 5 mhz input clock the on-chip logic may be run at a frequency down to 156.25 khz (or 78 khz) without an external hardware change. an implemented pll may be switched off in this case or kept running, depending on the requirements of the application (see table 21-2 ). note: during slow down operation the whole device (including bus interface and generation of signals clkout or fout) is clocked with the sdd clock (see figure 21-3 ). mcd04477 f osc f sdd reload counter clkrel f osc f sdd factor = 3, prescaler factor = 5, direct drive factor = 3, direct drive
c167cs derivatives power management users manual 21-11 v2.0, 2000-07 all these clock options are selected via bitfield clkcon in register syscon2. a state machine controls the switching mechanism itself and ensures a continuous and glitch- free clock signal to the on-chip logic. this is especially important when switching back to pll frequency when the pll has temporarily been switched off. in this case the clock source can be switched back either automatically as soon as the pll is locked again (indicated by bit clklock in register syscon2), or manually, i.e. under software control, after bit clklock has become 1. the latter way is preferable if the application requires a defined point where the frequency changes. note: when the pll is the basic clock source and a reset occurs during sdd operation with the pll off, the internal reset condition is extended so the pll can lock before execution begins. the reset condition is terminated prematurely if no stable oscillator clock is detected. this ensures the operability of the device in case of a missing input clock signal. switching to slow down operation affects frequency sensitive peripherals like serial interfaces, timers, pwm, etc. if these units are to be operated in slow down mode their precalers or reload values must be adapted. please note that the reduced cpu frequency decreases e.g. timer resolution and increases the step width e.g. for baudrate generation. the oscillator frequency in such a case should be chosen to accomodate the required resolutions and/or baudrates. table 21-2 pll operation in slow down mode advantage disadvantage oscillator watchdog pll running fast switching back to basic clock source pll adds to power consumption active if not disabled via bit owddis pll off pll causes no additional power consumption pll must lock before switching back to the basic clock source (if the pll is the basic clock source) disabled
c167cs derivatives power management users manual 21-12 v2.0, 2000-07 note: syscon2 (except for bitfield sysrls, of course) is write protected after the execution of einit unless it is released via the unlock sequence (see table 21-6 ). syscon2 system control reg.2 esfr (f1d0 h /e8 h ) reset value: 00x0 h 1514131211109876543210 clk lock clkrel clkcon scs rcs pdcon sysrls r rw rw rw rw rw rw bit function sysrls register release function (unlock field) must be written in a defined way in order to execute the unlock sequence. see separate description ( table 21-6 ). pdcon power down control (during power down mode) 00: rtc = on, ports = on (default after reset). 01: rtc = on, ports = off. 10: rtc = off, ports = on. 11: rtc = off, ports = off. rcs rtc clock source (not affected by a reset!) 0: main oscillator. 1: reserved. scs sdd clock source (not affected by a reset!) 0: main oscillator. 1: reserved. clkcon clock state control 00: running on configured basic frequency. 01: running on slow down frequency, pll remains on. 10: running on slow down frequency, pll switched off. 11: reserved. do not use this combination. clkrel reload counter value for slowdown divider (sdd factor = clkrel+1) clklock clock signal status bit 0: main oscillator is unstable or pll is unlocked. 1: main oscillator is stable and pll is locked.
c167cs derivatives power management users manual 21-13 v2.0, 2000-07 figure 21-4 clock switching state machine table 21-3 clock switching state description state number pll status f cpu source clk con note 1 locked 1) 1) the indicated pll status only applies if the pll is selected as the basic clock source. if the basic clock source is direct drive or prescaler the pll will not lock. if the oscillator watchdog is disabled (owddis = 1) the pll will be off. basic 00 standard operation on basic clock frequency. 2 locked 1) sdd 01 sdd operation with pll on 1) . fast (without delay) or manual switch back (from 5) to basic clock frequency. 3 transient 1) sdd (00) intermediate state leading to state 1. 4 transient 1) sdd (01) intermediate state leading to state 2. 5 off sdd 10 sdd operation with pll off. reduced power consumption. mca04478 01 00 01 00 2 1 10 10 3 5 4 00 01 10 10 reset xx state transition when writing "xx" to clkcon. automatic transition after clock is stable, i.e. clklock = '1'.
c167cs derivatives power management users manual 21-14 v2.0, 2000-07 21.5 flexible peripheral management the power consumed by the c167cs also depends on the amount of active logic. peripheral management enables the system designer to deactivate those on-chip peripherals that are not required in a given system status (e.g. a certain interface mode or standby). all modules that remain active, however, will still deliver their usual performance. if all modules that are fed by the peripheral clock driver (pcd) are disabled and also the other functions fed by the pcd are not required, this clock driver itself may also be disabled to save additional power. this flexibility is realized by distributing the cpu clock via several clock drivers which can be separately controlled, and may also be smaller. figure 21-5 cpu clock distribution note: the real time clock (rtc) is fed by a separate clock driver, so it can be kept running even in power down mode while still all the other circuitry is disconnected from the clock. the registers of the generic peripherals can be accessed even while the respective module is disabled, as long as pcd is running (the registers of peripherals which are connected to icd can be accessed even in this case, of course). the registers of x- peripherals cannot be accessed while the respective module is disabled by any means. while a peripheral is disabled its output pins remain in the state they had at the time of disabling. software controls this flexible peripheral mangement via register syscon3 where each control bit is associated with an on-chip peripheral module. rtc ccd pcd clock generation icd interface peripherals, fout peripherals, ports, intr. ctrl. pcddis cpu idle mode mca04479
c167cs derivatives power management users manual 21-15 v2.0, 2000-07 note: the allocation of peripheral disable bits within register syscon3 is device specific and may be different in other derivatives than the c167cs. syscon3 is write protected after the execution of einit unless it is released via the unlock sequence (see table 21-6 ). syscon3 system control reg.3 esfr (f1d4 h /ea h ) reset value: 0000 h 1514131211109876543210 pcd dis can2 dis can1 dis --- pwm dis - cc2 dis cc1 dis -- gpt dis ssc dis asc 0 dis adc dis rw rw rw - - - rw - rw rw - - rw rw rw rw bit function (associated peripheral module) adcdis analog/digital converter asc0dis usart asc0 sscdis synchronous serial channel ssc gptdis general purpose timer blocks cc1dis capcom unit 1 cc2dis capcom unit 2 pwmdis pulse width modulation unit can1dis on-chip can module 1 1) can2dis on-chip can module 2 1) pcddis peripheral clock driver (also x-peripherals) 1) when bit canxdis is cleared the can module is re-activated by an internal reset signal and must then be re- configured in order to operate properly.
c167cs derivatives power management users manual 21-16 v2.0, 2000-07 when disabling the peripheral clock driver (pcd), the following details should be respected: ? the clock signal for all connected peripherals is stopped. make sure that all peripherals enter a safe state before disabling pcd. ? the output signal clkout will remain high (fout will keep on toggling). ? interrupt requests will still be recognized even while pcd is disabled. ? no new output values are gated from the port output latches to the output port pins and no new input values are latched from the input port pins. ? no register access is possible for generic peripherals. (register access is possible for individually disabled generic peripherals, no register access at all is possible for disabled x-peripherals).
c167cs derivatives power management users manual 21-17 v2.0, 2000-07 21.6 programmable frequency output signal the system clock output (clkout) can be replaced by the programmable frequency output signal f out . this signal can be controlled via software (contrary to clkout), and so can be adapted to the requirements of the connected external circuitry. the programmability also extends the power management to a system level, as also circuitry (peripherals, etc.) outside the c167cs can be influenced, i.e. run at a scalable frequency or temporarily can be switched off completely. this clock signal is generated via a reload counter, so the output frequency can be selected in small steps. an optional toggle latch provides a clock signal with a 50% duty cycle. figure 21-6 clock output signal generation signal f out always provides complete output periods (see signal waveforms below): ? when f out is started (foen --> 1) focnt is loaded from forv ? when f out is stopped (foen --> 0) focnt is stopped when f out has reached (or is) 0. signal f out is independent from the peripheral clock driver pcd. while clkout would stop when pcd is disabled, f out will keep on toggling. thus external circuitry may be controlled independent from on-chip peripherals. note: counter focnt is clocked with the cpu clock signal f cpu (see figure 21-6 ) and therefore will also be influenced by the sdd operation. register focon provides control over the output signal generation (frequency, waveform, activation) as well as all status information (counter value, fotl). mca04480 focnt forv ctrl. foen f cpu fotl mux f out foss
c167cs derivatives power management users manual 21-18 v2.0, 2000-07 note: it is not recommended to write to any part of bitfield focnt, especially not while the counter is running. writing to focnt prior to starting the counter is obsolete because it will immediatley be reloaded from forv. writing to focnt during operation may produce unintended counter values. focon frequ.output control reg. sfr (ffaa h /d5 h ) reset value: 0000 h 1514131211109876543210 fo en fo ss forv - fo tl focnt rw rw rw - rw rw bit function focnt frequency output counter fotl frequency output toggle latch is toggled upon each underflow of focnt. forv frequency output reload value is copied to focnt upon each underflow of focnt. foss frequency output signal select 0: output of the toggle latch: duty cycle = 50%. 1: output of the reload counter: duty cycle depends on forv. foen frequency output enable 0: frequency output generation stops when signal f out is/gets low. 1: focnt is running, f out is gated to pin. first reload after 0-1 transition.
c167cs derivatives power management users manual 21-19 v2.0, 2000-07 signal f out in the c167cs is an alternate function of pin p3.15/clkout/fout. figure 21-7 connection to port logic (functional approach) a priority ranking determines which function controls the shared pin: note: for the generation of f out pin fout must be switched to output, i.e. dp3.15 = 1. while f out is disabled the pin is controlled by the port latch (see figure 21-7 ). the port latch p3.15 must be 0 in order to maintain the f out inactive level on the pin. table 21-4 priority ranking for shared output pin priority function control 1 clkout clken = 1, foen = x 2 fout clken = 0, foen = 1 3 general purpose io clken = 0, foen = 0 mca04481 mux 0 1 mux 0 1 fout f cpu f out portlatch fout_active mux 0 1 clken "1" direction
c167cs derivatives power management users manual 21-20 v2.0, 2000-07 figure 21-8 signal waveforms note: the output signal (for foss = 1) is high for the duration of one f cpu cycle for all reload values forv > 0. for forv = 0 the output signal corresponds to f cpu . mct04482 f cpu f out (forv = 0) 1) 2) 1) 2) f out (forv = 2) 1) 2) f out (forv = 5) foen '1' 1) foss = '1', output of counter 2) foss = '0', output of toggle latch foen '0' the counter starts here the counter stops here
c167cs derivatives power management users manual 21-21 v2.0, 2000-07 output frequency calculation the output frequency can be calculated as f out = f cpu / ((forv + 1) 2 (1 C foss) ), so f outmin = f cpu / 128 (forv = 3f h , foss = 0), and f outmax = f cpu / 1 (forv = 00 h , foss = 1). table 21-5 selectable output frequency range for f out f cpu f out in [khz] for forv = xx, foss = 1/0 forv for f out = 1 mhz 00 h 01 h 02 h 3e h 3f h foss = 0 foss = 1 4 mhz 4000 2000 2000 1000 1333.33 666.67 63.492 31.746 62.5 31.25 01 h 03 h 10 mhz 10000 5000 5000 2500 3333.33 1666.67 158.73 79.365 156.25 78.125 04 h 09 h 12 mhz 12000 6000 6000 3000 4000 2000 190.476 95.238 187.5 93.75 05 h 0b h 16 mhz 16000 8000 8000 4000 5333.33 2666.67 253.968 126.984 250 125 07 h 0f h 20 mhz 20000 10000 10000 5000 6666.67 3333.33 317.46 158.73 312.5 156.25 09 h 13 h 25 mhz 25000 12500 12500 6250 8333.33 4166.67 396.825 198.413 390.625 195.313 0b h (1.04167) 0c h (0.96154) 18 h 33 mhz 33000 16500 16500 8250 11000 5500 523.810 261.905 515.625 257.816 0f h (1.03125) 10 h (0.97059) 20 h
c167cs derivatives power management users manual 21-22 v2.0, 2000-07 21.7 security mechanism the power management control registers belong to a set of registers (see table 21-7 ) which control functions and modes which are critical for the c167css operation. for this reason they are locked (except for bitfield sysrls in register syscon2) after the execution of einit (like register syscon) so these vital system functions cannot be changed inadvertently e.g. by software errors. however, as these registers control important functions (e.g. the power management) they need to be accessed during operation to select the appropriate mode. the system control software gets this access via a special unlock sequence which allows one single write access to one register of this set when executed properly. this provides a maximum of security. note: of course all these registers may be read at any time without restrictions. the unlock sequence is executed by writing defined values to bitfield sysrls using defined instructions (see table 21-6 ). the instructions of the unlock sequence (including the intended write access) must be secured with an extr instruction (switch to esfr space and lock interrupts). note: the unlock sequence is aborted if the locked range (extr) does not cover the complete sequence. the unlock sequence provides no write access to register syscon. table 21-6 unlock sequence for secured registers step sysrls instruction notes C 0000 b 1) 1) sysrls must be set to 0000 b before the first step, if any or command is used. C status before release sequence 1 1001 b bfldl, or, orb 2) , xor, xorb 2) 2) usually byte accesses should not be used for special function registers. read-modify-write access 2 0011 b mov, movb 2) , movbs 2) , movbz 2) write access 3 0111 b bset, bmov 2) , bmovn 2) , bor 2) , bxor 2) read-modify-write access, bit instruction 4 C C single (read-modify-)write access to syscon1, syscon2, or syscon3. C 0000 b 3) 3) sysrls is cleared by hardware if unlock sequence and write access were successful. sysrls shows the last value written otherwise. C status after release sequence
c167cs derivatives power management users manual 21-23 v2.0, 2000-07 the following registers are secured by the described unlock sequence: code examples the code examples below show how the unlock sequence is used to access register syscon2 (marked *!* in the comment column) in an application in order to change the basic clock generation mode. examples where the pll keeps running: ;________________________ ;____________________________________ enter_slowdown: ;currently running on basic clock frequ. mov syscon2, zeros ;clear bits 3-0 (no extr required here) extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to one locked register bfldh syscon2,#03h,#01h ;clkcon=01b --> sdd frequency, pll on*!* ;_______________________ ;_____________________________________ exit_slowdown: ;currently running on sdd frequency mov syscon2, zeros ;clear bits 3-0 (no extr required here) extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to one locked register bfldh syscon2,#03h,#00h ;clkcon=00b --> basic frequency *!* table 21-7 special registers secured by the unlock sequence register name description syscon1 controls sleep mode syscon2 controls clock generation (sdd) and the unlock sequence itself syscon3 controls the flexible peripheral management rstcon controls the configuration of the c167cs (basic clock generation mode, cs lines, segment address width) and the length of the reset sequence
c167cs derivatives power management users manual 21-24 v2.0, 2000-07 examples where the pll is disabled: ;________________________ ;_____________________________________ enter_slowdown: ;currently running on basic clock frequ. extr #1h ;next access to esfr space bclr isnc.2 ;pllie=0, i.e. pll interrupt disabled mov syscon2, zeros ;clear bits 3-0 (no extr required here) extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to one locked register bfldh syscon2,#03h,#02h ;clkcon=10b-->sdd frequency, pll off*!* ;________________________ ;_____________________________________ sdd_exit_auto: ;currently running on sdd frequency mov syscon2, zeros ;clear bits 3-0 (no extr required here) extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to one locked register bfldh syscon2,#03h,#00h ;clkcon=00b-->basic frequ./start pll*!* extr #1h ;next access to esfr space bset isnc.2 ;pllie=1, i.e. pll interrupt enabled
c167cs derivatives power management users manual 21-25 v2.0, 2000-07 ;________________________ ;_____________________________________ sdd_exit_manual: ;currently running on sdd frequency mov syscon2, zeros ;clear bits 3-0 (no extr required here) extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to one locked register bfldh syscon2,#03h,#01h ;clkcon=01b-->stay on sdd/start pll *!* ; user_code: ;space for any user code that... ;...must or can be executed before... ;...switching back to basic clock clock_ok: extr #1h ;next access to esfr space jnb syscon2.15,clock_ok;wait until clock ok (clklock=1) ; mov syscon2, zeros ;clear bits 3-0 (no extr required here) extr #4h ;switch to esfr space and lock sequence bfldl syscon2,#0fh,#09h ;unlock sequence, step 1 (1001b) mov syscon2,#0003h ;unlock sequence, step 2 (0011b) bset syscon2.2 ;unlock sequence, step 3 (0111b) ;single access to one locked register bfldh syscon2,#03h,#00h ;clkcon=00b --> basic frequency *!* extr #1h ;next access to esfr space bset isnc.2 ;pllie=1, i.e. pll interrupt enabled
c167cs derivatives system programming users manual 22-1 v2.0, 2000-07 22 system programming to aid in software development, a number of features has been incorporated into the instruction set of the c167cs, including constructs for modularity, loops, and context switching. in many cases commonly used instruction sequences have been simplified while providing greater flexibility. the following programming features help to fully utilize this instruction set. instructions provided as subsets of instructions in many cases, instructions found in other microcontrollers are provided as subsets of more powerful instructions in the c167cs. this allows the same functionality to be provided while decreasing the hardware required and decreasing decode complexity. in order to aid assembly programming, these instructions, familiar from other microcontrollers, can be built in macros, thus providing the same names. directly substitutable instructions are instructions known from other microcontrollers that can be replaced by the following instructions of the c167cs: modification of system flags is performed using bit set or bit clear instructions (bset, bclr). all bit and word instructions can access the psw register, so no instructions like clear carry or enable interrupts are required. external memory data access does not require special instructions to load data pointers or explicitly load and store external data. the c167cs provides a von neumann memory architecture and its on-chip hardware automatically detects accesses to internal ram, gprs, and sfrs. multiplication and division multiplication and division of words and double words is provided through multiple cycle instructions implementing a booth algorithm. each instruction implicitly uses the 32-bit register md (mdl = lower 16 bits, mdh = upper 16 bits). the mdriu flag (multiply or divide register in use) in register mdc is set whenever either half of this register is written to or when a multiply/divide instruction is started. it is cleared whenever the mdl table 22-1 substitution of instructions substituted instruction c167cs instruction function clr rn and rn, #0 h clear register cplb bit bmovn bit, bit complement bit dec rn sub rn, #1 h decrement register inc rn add rn, #1 h increment register swapb rn ror rn, #8 h swap bytes within word
c167cs derivatives system programming users manual 22-2 v2.0, 2000-07 register is read. because an interrupt can be acknowledged before the contents of register md are saved, this flag is required to alert interrupt routines, which require the use of the multiply/divide hardware, so they can preserve register md. this register, however, only needs to be saved when an interrupt routine requires use of the md register and a previous task has not saved the current result. this flag is easily tested by the jump-on-bit instructions. multiplication or division is simply performed by specifying the correct (signed or unsigned) version of the multiply or divide instruction. the result is then stored in register md. the overflow flag (v) is set if the result from a multiply or divide instruction is greater than 16 bits. this flag can be used to determine whether both word halfs must be transferred from register md. the high portion of register md (mdh) must be moved into the register file or memory first, in order to ensure that the mdriu flag reflects the correct state. the following instruction sequence performs an unsigned 16 by 16-bit multiplication: save: jnb mdriu, start;test if md was in use. scxt mdc, #0010h ;save and clear control register, ;leaving mdriu set ;(only required for interrupted ;multiply/divide instructions) bset saved ;indicate the save operation push mdh ;save previous md contents push mdl ; on system stack start: mulu r1, r2 ;multiply 1616 unsigned, sets mdriu jmpr cc_nv, copyl;test for only 16-bit result mov r3, mdh ;move high portion of md copyl: mov r4, mdl ;move low portion of md, clears mdriu restore: jnb saved, done ;test if md registers were saved pop mdl ;restore registers pop mdh pop mdc bclr saved ;multiplication is completed, ;program continues done:
c167cs derivatives system programming users manual 22-3 v2.0, 2000-07 the above save sequence and the restore sequence after copyl are only required if the current routine could have interrupted a previous routine which contained a mul or div instruction. register mdc is also saved because it is possible that a previous routines multiply or divide instruction was interrupted while in progress. in this case the information about how to restart the instruction is contained in this register. register mdc must be cleared to be correctly initialized for a subsequent multiplication or division. the old mdc contents must be popped from the stack before the reti instruction is executed. for a division the user must first move the dividend into the md register. if a 16/16-bit division is specified, only the low portion of register md must be loaded. the result is also stored into register md. the low portion (mdl) contains the integer result of the division, while the high portion (mdh) contains the remainder. the following instruction sequence performs a 32 by 16-bit division: mov mdh, r1 ;move dividend to md register. sets mdriu mov mdl, r2 ;move low portion to md div r3 ;divide 32/16 signed, r3 holds divisor jmpr cc_v, error ;test for divide overflow mov r3, mdh ;move remainder to r3 mov r4, mdl ; move integer result to r4. clears mdriu whenever a multiply or divide instruction is interrupted while in progress, the address of the interrupted instruction is pushed onto the stack and the mulip flag in the psw of the interrupting routine is set. when the interrupt routine is exited with the reti instruction, this bit is implicitly tested before the old psw is popped from the stack. if mulip = 1 the multiply/divide instruction is re-read from the location popped from the stack (return address) and will be completed after the reti instruction has been executed. note: the mulip flag is part of the context of the interrupted task . when the interrupting routine does not return to the interrupted task (e.g. scheduler switches to another task) the mulip flag must be set or cleared according to the context of the task that is switched to. bcd calculations no direct support for bcd calculations is provided in the c167cs. bcd calculations are performed by converting bcd data to binary data, performing the desired calculations using standard data types, and converting the result back to bcd data. due to the enhanced performance of division instructions binary data is quickly converted to bcd data through division by 10 d . conversion from bcd data to binary data is enhanced by multiple bit shift instructions. this provides similar performance compared to instructions directly supporting bcd data types, while no additional hardware is required.
c167cs derivatives system programming users manual 22-4 v2.0, 2000-07 22.1 stack operations the c167cs supports two types of stacks. the system stack is used implicitly by the controller and is located in the internal ram. the user stack provides stack access to the user in either the internal or external memory. both stack types grow from high memory addresses to low memory addresses. internal system stack a system stack is provided to store return vectors, segment pointers, and processor status for procedures and interrupt routines. a system register, sp, points to the top of the stack. this pointer is decremented when data is pushed onto the stack, and incremented when data is popped. the internal system stack can also be used to temporarily store data or pass it between subroutines or tasks. instructions are provided to push or pop registers on/from the system stack. however, in most cases the register banking scheme provides the best performance for passing data between multiple tasks. note: the system stack allows the storage of words only. bytes must either be converted to words or the respective other byte must be disregarded. register sp can only be loaded with even byte addresses (the lsb of sp is always 0). detection of stack overflow/underflow is supported by two registers, stkov (stack overflow pointer) and stkun (stack underflow pointer). specific system traps (stack overflow trap, stack underflow trap) will be entered whenever the sp reaches either boundary specified in these registers. the contents of the stack pointer are compared to the contents of the overflow register, whenever the sp is decremented either by a call, push or sub instruction. an overflow trap will be entered, when the sp value is less than the value in the stack overflow register. the contents of the stack pointer are compared to the contents of the underflow register, whenever the sp is incremented either by a ret, pop or add instruction. an underflow trap will be entered, when the sp value is greater than the value in the stack underflow register. note: when a value is moved into the stack pointer, no check against the overflow/ underflow registers is performed. in many cases the user will place a software reset instruction (srst) into the stack underflow and overflow trap service routines. this is an easy approach, which does not require special programming. however, this approach assumes that the defined internal stack is sufficient for the current software and that exceeding its upper or lower boundary represents a fatal error.
c167cs derivatives system programming users manual 22-5 v2.0, 2000-07 it is also possible to use the stack underflow and stack overflow traps to cache portions of a larger external stack. only the portion of the system stack currently being used is placed into the internal memory, thus allowing a greater portion of the internal ram to be used for program, data or register banking. this approach assumes no error but requires a set of control routines (see below). circular (virtual) stack this basic technique allows pushing until the overflow boundary of the internal stack is reached. at this point a portion of the stacked data must be saved into external memory to create space for further stack pushes. this is called stack flushing. when executing a number of return or pop instructions, the upper boundary (since the stack empties upward to higher memory locations) is reached. the entries that have been previously saved in external memory must now be restored. this is called stack filling. because procedure call instructions do not continue to nest infinitely and call and return instructions alternate, flushing and filling normally occurs very infrequently. if this is not true for a given program environment, this technique should not be used because of the overhead of flushing and filling. the basic mechanism is the transformation of the addresses of a virtual stack area, controlled via registers sp, stkov and stkun, to a defined physical stack area within the internal ram via hardware. this virtual stack area covers all possible locations that sp can point to, i.e. 00f000 h through 00fffe h . stkov and stkun accept the same 4 kbyte address range. the size of the physical stack area within the internal ram that effectively is used for standard stack operations is defined via bitfield stksz in register syscon (see below). table 22-2 circular stack address transformation stksz stack size (words) internal ram addresses (words) of physical stack significant bits of stack ptr. sp 0 0 0 b 256 00fbfe h 00fa00 h (default after reset) sp.8 sp.0 0 0 1 b 128 00fbfe h 00fb00 h sp.7 sp.0 0 1 0 b 64 00fbfe h 00fb80 h sp.6 sp.0 0 1 1 b 32 00fbfe h 00fbc0 h sp.5 sp.0 1 0 0 b 512 00fbfe h 00f800 h (not for 1kbyte iram) sp.9 sp.0 1 0 1 b C reserved. do not use this combination. C 1 1 0 b C reserved. do not use this combination. C 1 1 1 b 512 / 1024 / 1536 00fdfe h 00fx00 h (note: no circular stack) 00fx00 h represents the lower iram limit, i.e. 1 kb: 00fa00 h , 2 kb: 00f600 h , 3 kb: 00f200 h sp.11 sp.0
c167cs derivatives system programming users manual 22-6 v2.0, 2000-07 the virtual stack addresses are transformed to physical stack addresses by concatenating the significant bits of the stack pointer register sp (see table 22-2 ) with the complementary most significant bits of the upper limit of the physical stack area (00fbfe h ). this transformation is done via hardware (see figure 22-1 ). the reset values (stkov = fa00 h , stkun = fc00 h , sp = fc00 h , stksz = 000 b ) map the virtual stack area directly to the physical stack area and allow using the internal system stack without any changes, provided that the 256 word area is not exceeded. figure 22-1 physical stack address generation the following example demonstrates the circular stack mechanism which is also an effect of this virtual stack mapping: first, register r1 is pushed onto the lowest physical stack location according to the selected maximum stack size. with the following instruction, register r2 will be pushed onto the highest physical stack location although the sp is decremented by 2 as for the previous push operation. mov sp, #0f802h ;set sp before last entry ; of physical stack of 256 words ;(sp)= f802h: physical stack addr.= fa02h push r1 ;(sp)= f800h: physical stack addr.= fa00h push r2 ;(sp)= f7feh: physical stack addr.= fbfeh mca04408 1111 1011 1111 1110 fbfe h 1111 1011 1111 1110 fbfe h fb80 h 0 0 0 0 0 0 0 1 1 1 0 1 1 1 1 1 phys.a. 1111 1011 1000 0000 fb80 h fa00 h 0 0 0 0 0 0 0 0 0 1 0 1 1 1 1 1 f800 h 0 0 0 0 0 0 0 0 0 0 0 1 1 1 1 1 1111 1011 1111 1110 fbfe h 1111 1011 1111 1110 fbfe h fbfe h 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 phys.a. 1111 1011 0111 1110 fb7e h fbfe h 0 1 1 1 1 1 1 1 1 1 0 1 1 1 1 1 f7fe h 0 1 1 1 1 1 1 1 1 1 1 0 1 1 1 1 after push after push 64 words 256 words stack size
c167cs derivatives system programming users manual 22-7 v2.0, 2000-07 the effect of the address transformation is that the physical stack addresses wrap around from the end of the defined area to its beginning. when flushing and filling the internal stack, this circular stack mechanism only requires to move that portion of stack data which is really to be re-used (i.e. the upper part of the defined stack area) instead of the whole stack area. stack data that remain in the lower part of the internal stack need not be moved by the distance of the space being flushed or filled, as the stack pointer automatically wraps around to the beginning of the freed part of the stack area. note: this circular stack technique is applicable for stack sizes of 32 to 512 words (stksz = 000 b to 100 b ), it does not work with option stksz = 111 b , which uses the complete internal ram for system stack. in the latter case the address transformation mechanism is deactivated. when a boundary is reached, the stack underflow or overflow trap is entered, where the user moves a predetermined portion of the internal stack to or from the external stack. the amount of data transferred is determined by the average stack space required by routines and the frequency of calls, traps, interrupts and returns. in most cases this will be approximately one quarter to one tenth the size of the internal stack. once the transfer is complete, the boundary pointers are updated to reflect the newly allocated space on the internal stack. thus, the user is free to write code without concern for the internal stack limits. only the execution time required by the trap routines affects user programs. the following procedure initializes the controller for usage of the circular stack mechanism: ? specify the size of the physical system stack area within the internal ram (bitfield stksz in register syscon). ? define two pointers, which specify the upper and lower boundary of the external stack. these values are then tested in the stack underflow and overflow trap routines when moving data. ? set the stack overflow pointer (stkov) to the limit of the defined internal stack area plus six words (for the reserved space to store two interrupt entries). the internal stack will now fill until the overflow pointer is reached. after entry into the overflow trap procedure, the top of the stack will be copied to the external memory. the internal pointers will then be modified to reflect the newly allocated space. after exiting from the trap procedure, the internal stack will wrap around to the top of the internal stack, and continue to grow until the new value of the stack overflow pointer is reached. when the underflow pointer is reached while the stack is meptied the bottom of stack is reloaded from the external memory and the internal pointers are adjusted accordingly.
c167cs derivatives system programming users manual 22-8 v2.0, 2000-07 linear stack the c167cs also offers a linear stack option (stksz = 111 b ), where the system stack may use the complete internal ram area. this provides a large system stack without requiring procedures to handle data transfers for a circular stack. however, this method also leaves less ram space for variables or code. the ram area that may effectively be consumed by the system stack is defined via the stkun and stkov pointers. the underflow and overflow traps in this case serve for fatal error detection only. for the linear stack option all modifiable bits of register sp are used to access the physical stack. although the stack pointer may cover addresses from 00f000 h up to 00fffe h the (physical) system stack must be located within the internal ram and therefore may only use the address range 00f200 h /00f600 h /00fa00 h to 00fdfe h . it is the users responsibility to restrict the system stack to the internal ram range. note: avoid stack accesses below the iram area (esfr space and reserved area) and within address range 00fe00 h and 00fffe h (sfr space). otherwise unpredictable results will occur. user stacks user stacks provide the ability to create task specific data stacks and to off-load data from the system stack. the user may push both bytes and words onto a user stack, but is responsible for using the appropriate instructions when popping data from the specific user stack. no hardware detection of overflow or underflow of a user stack is provided. the following addressing modes allow implementation of user stacks: [Crw], rb or [Crw], rw : pre-decrement indirect addressing. used to push one byte or word onto a user stack. this mode is only available for mov instructions and can specify any gpr as the user stack pointer. rb, [rw i +] or rw, [rw i +] : post-increment index register indirect addressing. used to pop one byte or word from a user stack. this mode is available to most instructions, but only gprs r0-r3 can be specified as the user stack pointer. rb, [rw+] or rw, [rw+] : post-increment indirect addressing. used to pop one byte or word from a user stack. this mode is only available for mov instructions and can specify any gpr as the user stack pointer.
c167cs derivatives system programming users manual 22-9 v2.0, 2000-07 22.2 register banking register banking provides the user with an extremely fast method to switch user context. a single machine cycle instruction saves the old bank and enters a new register bank. each register bank may assign up to 16 registers. each register bank should be allocated during coding based on the needs of each task. once the internal memory has been partitioned into a register bank space, internal stack space and a global internal memory area, each bank pointer is then assigned. thus, upon entry into a new task, the appropriate bank pointer is used as the operand for the scxt (switch context) instruction. upon exit from a task a simple pop instruction to the context pointer (cp) restores the previous task s register bank. 22.3 procedure call entry and exit to support modular programming a procedure mechanism is provided to allow coding of frequently used portions of code into subroutines. the call and ret instructions store and restore the value of the instruction pointer (ip) on the system stack before and after a subroutine is executed. procedures may be called conditionally with instructions calla or calli, or be called unconditionally using instructions callr or calls. note: any data pushed onto the system stack during execution of the subroutine must be popped before the ret instruction is executed. passing parameters on the system stack parameters may be passed via the system stack through push instructions before the subroutine is called, and pop instructions during execution of the subroutine. base plus offset indirect addressing also permits access to parameters without popping these parameters from the stack during execution of the subroutine. indirect addressing provides a mechanism of accessing data referenced by data pointers, which are passed to the subroutine. in addition, two instructions have been implemented to allow one parameter to be passed on the system stack without additional software overhead. the pcall (push and call) instruction first pushes the reg operand and the ip contents onto the system stack and then passes control to the subroutine specified by the caddr operand. when exiting from the subroutine, the retp (return and pop) instruction first pops the ip and then the reg operand from the system stack and returns to the calling program.
c167cs derivatives system programming users manual 22-10 v2.0, 2000-07 cross segment subroutine calls calls to subroutines in different segments require the use of the calls (call inter- segment subroutine) instruction. this instruction preserves both the csp (code segment pointer) and ip on the system stack. upon return from the subroutine, a rets (return from inter-segment subroutine) instruction must be used to restore both the csp and ip. this ensures that the next instruction after the calls instruction is fetched from the correct segment. note: it is possible to use calls within the same segment, but still two words of the stack are used to store both the ip and csp. providing local registers for subroutines for subroutines which require local storage, the following methods are provided: alternate bank of registers: upon entry into a subroutine, it is possible to specify a new set of local registers by executing the scxt (switch context) instruction. this mechanism does not provide a method to recursively call a subroutine. saving and restoring of registers: to provide local registers, the contents of the registers which are required for use by the subroutine can be pushed onto the stack and the previous values be popped before returning to the calling routine. this is the most common technique used today and it does provide a mechanism to support recursive procedures. this method, however, requires two machine cycles per register stored on the system stack (one cycle to push the register, and one to pop the register). use of the system stack for local registers: it is possible to use the sp and cp to set up local subroutine register frames. this enables subroutines to dynamically allocate local variables as needed within two machine cycles. a local frame is allocated by simply subtracting the number of required local registers from the sp, and then moving the value of the new sp to the cp. this operation is supported through the scxt (switch context) instruction with the addressing mode reg, mem. using this instruction saves the old contents of the cp on the system stack and moves the value of the sp into cp (see example below). each local register is then accessed as if it was a normal register. upon exit from the subroutine, first the old cp must be restored by popping it from the stack and then the number of used local registers must be added to the sp to restore the allocated local space back to the system stack. note: the system stack is growing downwards, while the register bank is growing upwards.
c167cs derivatives system programming users manual 22-11 v2.0, 2000-07 figure 22-2 local registers the software to provide the local register bank for the example above is very compact: after entering the subroutine: sub sp, #10d ;free 5 words in the current system stack scxt cp, sp ;set the new register bank pointer before exiting the subroutine: pop cp ;restore the old register bank add sp, #10d ;release the 5 words ; of the current system stack r3 r4 r2 r1 r0 mca04409 old cpcontents new stack area newly allocated register bank old stack area old sp new cp new sp
c167cs derivatives system programming users manual 22-12 v2.0, 2000-07 22.4 table searching a number of features have been included to decrease the execution time required to search tables. first, branch delays are eliminated by the branch target cache after the first iteration of the loop. second, in non-sequentially searched tables, the enhanced performance of the alu allows more complicated hash algorithms to be processed to obtain better table distribution. for sequentially searched tables, the auto-increment indirect addressing mode and the e (end of table) flag stored in the psw decrease the number of overhead instructions executed in the loop. the two examples below illustrate searching ordered tables and non-ordered tables, respectively: mov r0, #base ;move table base into r0 loop: cmp r1, [r0+] ;compare target to table entry jmpr cc_sgt, loop;test whether target has not been found note: the last entry in the table must be greater than the largest possible target. mov r0, #base ;move table base into r0 loop: cmp r1, [r0+] ;compare target to table entry jmpr cc_net, loop;test whether target is not found and ; the end of table has not been reached. note: the last entry in the table must be equal to the lowest signed integer (8000 h ). 22.5 floating point support all floating point operations are performed using software. standard multiple precision instructions are used to perform calculations on data types that exceed the size of the alu. multiple bit rotate and logic instructions allow easy masking and extracting of portions of floating point numbers. to decrease the time required to perform floating point operations, two hardware features have been implemented in the cpu core. first, the prior instruction aids in normalizing floating point numbers by indicating the position of the first set bit in a gpr. this result can the be used to rotate the floating point result accordingly. the second feature aids in properly rounding the result of normalized floating point numbers through the overflow (v) flag in the psw. this flag is set when a one is shifted out of the carry bit during shift right operations. the overflow flag and the carry flag are then used to round the floating point result based on the desired rounding algorithm.
c167cs derivatives system programming users manual 22-13 v2.0, 2000-07 22.6 peripheral control and interface all communication between peripherals and the cpu is performed either by pec transfers to and from internal memory, or by explicitly addressing the sfrs associated with the specific peripherals. after resetting the c167cs all peripherals (except the watchdog timer) are disabled and initialized to default values. a desired configuration of a specific peripheral is programmed using mov instructions of either constants or memory values to specific sfrs. specific control flags may also be altered via bit instructions. once in operation, the peripheral operates autonomously until an end condition is reached at which time it requests a pec transfer or requests cpu servicing through an interrupt routine. information may also be polled from peripherals through read accesses to sfrs or bit operations including branch tests on specific control bits in sfrs. to ensure proper allocation of peripherals among multiple tasks, a portion of the internal memory has been made bit addressable to allow user semaphores. instructions have also been provided to lock out tasks via software by setting or clearing user specific bits and conditionally branching based on these specific bits. it is recommended that bit fields in control sfrs are updated using the bfldh and bfldl instructions or a mov instruction to avoid undesired intermediate modes of operation which can occur, when bclr/bset or and/or instruction sequences are used. 22.7 trap/interrupt entry and exit interrupt routines are entered when a requesting interrupt has a priority higher than the current cpu priority level. traps are entered regardless of the current cpu priority. when either a trap or interrupt routine is entered, the state of the machine is preserved on the system stack and a branch to the appropriate trap/interrupt vector is made. all trap and interrupt routines require the use of the reti (return from interrupt) instruction to exit from the called routine. this instruction restores the system state from the system stack and then branches back to the location where the trap or interrupt occurred.
c167cs derivatives system programming users manual 22-14 v2.0, 2000-07 22.8 unseparable instruction sequences the instructions of the c167cs are very efficient (most instructions execute in one machine cycle) and even the multiplication and division are interruptable in order to minimize the response latency to interrupt requests (internal and external). in many microcontroller applications this is vital. some special occasions, however, require certain code sequences (e.g. semaphore handling) to be uninterruptable to function properly. this can be provided by inhibiting interrupts during the respective code sequence by disabling and enabling them before and after the sequence. the necessary overhead may be reduced by means of the atomic instruction which allows locking 1 4 instructions to an unseparable code sequence, during which the interrupt system (standard interrupts and pec requests) and class a traps (nmi , stack overflow/underflow) are disabled. a class b trap (illegal opcode, illegal bus access, etc.), however, will interrupt the atomic sequence, since it indicates a severe hardware problem. the interrupt inhibit caused by an atomic instruction gets active immediately, i.e. no other instruction will enter the pipeline except the one that follows the atomic instruction, and no interrupt request will be serviced in between. all instructions requiring multiple cycles or hold states are regarded as one instruction in this sense (e.g. mul is one instruction). any instruction type can be used within an unseparable code sequence. atomic #3 ;the next 3 instr. are locked (no nop requ.) mov r0, #1234h ;instr. 1 (no other instr. enters pipeline!) mov r1, #5678h ;instr. 2 mul r0, r1 ;instr. 3: mul regarded as one instruction mov r2, mdl ;this instruction is out of the scope ; of the atomic instruction sequence note: as long as any class b trap is pending (any of the class b trap flags in register tfr is set) the atomic instruction will not work. clear the respective b trap flag at the beginning of a b trap routine if atomic shall be used within the routine. 22.9 overriding the dpp addressing mechanism the standard mechanism to access data locations uses one of the four data page pointers (dppx), which selects a 16-kbyte data page, and a 14-bit offset within this data page. the four dpps allow immediate access to up to 64 kbyte of data. in applications with big data arrays, especially in hll applications using large memory models, this may require frequent reloading of the dpps, even for single accesses.
c167cs derivatives system programming users manual 22-15 v2.0, 2000-07 the extp (extend page) instruction allows switching to an arbitrary data page for 1 4 instructions without having to change the current dpps. extp r15, #1 ;the override page number is stored in r15 mov r0, [r14] ;the (14-bit) page offset is stored in r14 mov r1, [r13] ;this instruction uses the std. dpp scheme! the exts (extend segment) instruction allows switching to a 64 kbyte segment oriented data access scheme for 1 4 instructions without having to change the current dpps. in this case all 16 bits of the operand address are used as segment offset, with the segment taken from the exts instruction. this greatly simplifies address calculation with continuous data like huge arrays in c. exts #15, #1 ; the override seg. is 15 (0f0000h..0fffffh) mov r0, [r14] ;the (16-bit) segment offset is stored in r14 mov r1, [r13] ;this instruction uses the std. dpp scheme! note: instructions extp and exts inhibit interrupts the same way as atomic. as long as any class b trap is pending (any of the class b trap flags in register tfr is set) the extend instructions will not work. clear the respective b trap flag at the beginning of a b trap routine if ext* shall be used within the routine. short addressing in the extended sfr (esfr) space the short addressing modes of the c167cs (reg or bitoff) implicitly access the sfr space. the additional esfr space would have to be accessed via long addressing modes (mem or [rw]). the extr (extend register) instruction redirects accesses in short addressing modes to the esfr space for 1 4 instructions, so the additional registers can be accessed this way, too. the extpr and extsr instructions combine the dpp override mechanism with the redirection to the esfr space using a single instruction. note: instructions extr, extpr and extsr inhibit interrupts the same way as atomic. the switching to the esfr area and data page overriding is checked by the development tools or handled automatically. nested locked sequences each of the described extension instruction and the atomic instruction starts an internal extension counter counting the effected instructions. when another extension or atomic instruction is contained in the current locked sequence this counter is restarted with the value of the new instruction. this allows the construction of locked sequences longer than 4 instructions. note: interrupt latencies may be increased when using locked code sequences. pec requests are not serviced during idle mode, if the idle instruction is part of a locked sequence.
c167cs derivatives system programming users manual 22-16 v2.0, 2000-07 22.10 handling the internal code memory the mask-rom/otp/flash versions of the c167cs provide on-chip code memory that may store code as well as data. the lower 32 kbyte of this code memory are referred to as the internal rom area. access to this internal rom area is controlled during the reset configuration and via software. the rom area may be mapped to segment 0, to segment 1 or the code memory may be disabled at all. note: the internal rom area always occupies an address area of 32 kbyte, even if the implemented mask rom/otp/flash memory is smaller than that (e.g. 8 kbyte). of course the total implemented memory may exceed 32 kbytes. code memory configuration during reset the control input pin ea (external access) enables the user to define the address area from which the first instructions after reset are fetched. when ea is low (0) during reset, the internal code memory is disabled and the first instructions are fetched from external memory. when ea is high (1) during reset, the internal code memory is globally enabled and the first instructions are fetched from the internal memory. note: be sure not to select internal memory access after reset on romless devices. mapping the internal rom area after reset the internal rom area is mapped into segment 0, the system segment (000000 h 007fff h ) as a default. this is necessary to allow the first instructions to be fetched from locations 000000 h ff. the rom area may be mapped to segment 1 (010000 h 017fff h ) by setting bit roms1 in register syscon. the internal rom area may now be accessed through the lower half of segment 1, while accesses to segment 0 will now be made to external memory. this adds flexibility to the system software. the interrupt/trap vector table, which uses locations 000000 h through 0001ff h , is now part of the external memory and may therefore be modified, i.e. the system software may now change interrupt/trap handlers according to the current condition of the system. the internal code memory can still be used for fixed software routines like io drivers, math libraries, application specific invariant routines, tables, etc. this combines the advantage of an integrated non-volatile memory with the advantage of a flexible, adaptable software system.
c167cs derivatives system programming users manual 22-17 v2.0, 2000-07 enabling and disabling the internal code memory after reset if the internal code memory does not contain an appropriate startup code, the system may be booted from external memory, while the internal memory is enabled afterwards to provide access to library routines, tables, etc. if the internal code memory only contains the startup code and/or test software, the system may be booted from internal memory, which may then be disabled, after the software has switched to executing from (e.g.) external memory, in order to free the address space occupied by the internal code memory, which is now unnecessary.
c167cs derivatives system programming users manual 22-18 v2.0, 2000-07 22.11 pits, traps and mines although handling the internal code memory provides powerful means to enhance the overall performance and flexibility of a system, extreme care must be taken in order to avoid a system crash. instruction memory is the most crucial resource for the c167cs and it must be made sure that it never runs out of it. the following precautions help to take advantage of the methods mentioned above without jeopardizing system security. internal code memory access after reset: when the first instructions are to be fetched from internal memory (ea = 1), the device must contain code memory, and this must contain a valid reset vector and valid code at its destination. mapping the internal rom area to segment 1: due to instruction pipelining, any new rom mapping will at the earliest become valid for the second instruction after the instruction which has changed the rom mapping. to enable accesses to the rom area after mapping a branch to the newly selected rom area (jmps) and reloading of all data page pointers is required. this also applies to re-mapping the internal rom area to segment 0. enabling the internal code memory after reset: when enabling the internal code memory after having booted the system from external memory, note that the c167cs will then access the internal memory using the current segment offset, rather than accessing external memory. disabling the internal code memory after reset: when disabling the internal code memory after having booted the system from there, note that the c167cs will not access external memory before a jump to segment 0 (in this case) is executed. general rules when mapping the code memory no instruction or data accesses should be made to the internal memory, otherwise unpredictable results may occur. to avoid these problems, the instructions that configure the internal code memory should be executed from external memory or from the on-chip ram. whenever the internal code memory is disabled, enabled or remapped the dpps must be explicitly (re)loaded to enable correct data accesses to the internal and/or external memory.
c167cs derivatives the register set users manual 23-1 v2.0, 2000-07 23 the register set this section summarizes all registers, which are implemented in the c167cs and explains the description format which is used in the chapters describing the function and layout of the sfrs. for easy reference the registers are ordered according to two different keys (except for gprs): ? ordered by address, to check which register a given address references, ? ordered by register name, to find the location of a specific register. 23.1 register description format in the respective chapters the function and the layout of the sfrs is described in a specific format which provides a number of details about the described special function register. the example below shows how to interpret these details. elements reg_name short name of this register a16/a8 long 16-bit address/short 8-bit address sfr /esfr / xreg register space (sfr, esfr or external/xbus register) (**) ** register contents after reset 0/1 : defined value, x : undefined, u : unchanged (undefined ( x ) after power up) r/w access modes: can be r ead and/or w rite bits that are set/cleared by hardware are marked with a shaded access box and an h in it. reg_name name of register e/sfr (a16 h /a8 h ) reset value: **** h 1514131211109876543210 std hw read/ write bit read bit write bit bitfield - - - - - - - - rw rwh rw r w rw bit function bit(field)name explanation of bit(field)name description of the functions controlled by the different possible values of this bit(field) . h
c167cs derivatives the register set users manual 23-2 v2.0, 2000-07 23.2 cpu general purpose registers (gprs) the gprs form the register bank that the cpu works with. this register bank may be located anywhere within the internal ram via the context pointer (cp). due to the addressing mechanism, gpr banks can only reside within the internal ram. all gprs are bit-addressable. table 23-1 general purpose word registers name physical address 8-bit address description reset value r0 (cp) + 0 f0 h cpu general purpose (word) reg. r0 uuuu h r1 (cp) + 2 f1 h cpu general purpose (word) reg. r1 uuuu h r2 (cp) + 4 f2 h cpu general purpose (word) reg. r2 uuuu h r3 (cp) + 6 f3 h cpu general purpose (word) reg. r3 uuuu h r4 (cp) + 8 f4 h cpu general purpose (word) reg. r4 uuuu h r5 (cp) + 10 f5 h cpu general purpose (word) reg. r5 uuuu h r6 (cp) + 12 f6 h cpu general purpose (word) reg. r6 uuuu h r7 (cp) + 14 f7 h cpu general purpose (word) reg. r7 uuuu h r8 (cp) + 16 f8 h cpu general purpose (word) reg. r8 uuuu h r9 (cp) + 18 f9 h cpu general purpose (word) reg. r9 uuuu h r10 (cp) + 20 fa h cpu general purpose (word) reg. r10 uuuu h r11 (cp) + 22 fb h cpu general purpose (word) reg. r11 uuuu h r12 (cp) + 24 fc h cpu general purpose (word) reg. r12 uuuu h r13 (cp) + 26 fd h cpu general purpose (word) reg. r13 uuuu h r14 (cp) + 28 fe h cpu general purpose (word) reg. r14 uuuu h r15 (cp) + 30 ff h cpu general purpose (word) reg. r15 uuuu h
c167cs derivatives the register set users manual 23-3 v2.0, 2000-07 the first 8 gprs (r7 r0) may also be accessed bytewise. other than with sfrs, writing to a gpr byte does not affect the other byte of the respective gpr. the respective halves of the byte-accessible registers receive special names: table 23-2 general purpose byte registers name physical address 8-bit address description reset value rl0 (cp) + 0 f0 h cpu general purpose (byte) reg. rl0 uu h rh0 (cp) + 1 f1 h cpu general purpose (byte) reg. rh0 uu h rl1 (cp) + 2 f2 h cpu general purpose (byte) reg. rl1 uu h rh1 (cp) + 3 f3 h cpu general purpose (byte) reg. rh1 uu h rl2 (cp) + 4 f4 h cpu general purpose (byte) reg. rl2 uu h rh2 (cp) + 5 f5 h cpu general purpose (byte) reg. rh2 uu h rl3 (cp) + 6 f6 h cpu general purpose (byte) reg. rl3 uu h rh3 (cp) + 7 f7 h cpu general purpose (byte) reg. rh3 uu h rl4 (cp) + 8 f8 h cpu general purpose (byte) reg. rl4 uu h rh4 (cp) + 9 f9 h cpu general purpose (byte) reg. rh4 uu h rl5 (cp) + 10 fa h cpu general purpose (byte) reg. rl5 uu h rh5 (cp) + 11 fb h cpu general purpose (byte) reg. rh5 uu h rl6 (cp) + 12 fc h cpu general purpose (byte) reg. rl6 uu h rh6 (cp) + 13 fd h cpu general purpose (byte) reg. rh6 uu h rl7 (cp) + 14 fe h cpu general purpose (byte) reg. rl7 uu h rh7 (cp) + 15 ff h cpu general purpose (byte) reg. rh7 uu h
c167cs derivatives the register set users manual 23-4 v2.0, 2000-07 23.3 special function registers ordered by name table 23-3 lists all sfrs which are implemented in the c167cs in alphabetical order. bit-addressable sfrs are marked with the letter b in column name. sfrs within the extended sfr-space (esfrs) are marked with the letter e in column physical address. registers within on-chip x-peripherals are marked with the letter x in column physical address. table 23-3 c167cs registers, ordered by name name physical address 8-bit addr. description reset value adcic b ff98 h cc h a/d converter end of conversion interrupt control register 0000 h adcon b ffa0 h d0 h a/d converter control register 0000 h addat fea0 h 50 h a/d converter result register 0000 h addat2 f0a0 h e 50 h a/d converter 2 result register 0000 h addrsel1 fe18 h 0c h address select register 1 0000 h addrsel2 fe1a h 0d h address select register 2 0000 h addrsel3 fe1c h 0e h address select register 3 0000 h addrsel4 fe1e h 0f h address select register 4 0000 h adeic b ff9a h cd h a/d converter overrun error interrupt control register 0000 h buscon0 b ff0c h 86 h bus configuration register 0 0000 h buscon1 b ff14 h 8a h bus configuration register 1 0000 h buscon2 b ff16 h 8b h bus configuration register 2 0000 h buscon3 b ff18 h 8c h bus configuration register 3 0000 h buscon4 b ff1a h 8d h bus configuration register 4 0000 h c1btr ef04 h x C can1 bit timing register uuuu h c1csr ef00 h x C can1 control/status register xx01 h c1gms ef06 h x C can1 global mask short ufuu h c1larn efn4 h x C can1 lower arbitration register (msg. n ) uuuu h c1lgml ef0a h x C can1 lower global mask long uuuu h c1lmlm ef0e h x C can1 lower mask of last message uuuu h c1mcfgn efn6 h x C can1 message configuration register (msg. n ) uu h c1mcrn efn0 h x C can1 message ctrl. reg. (msg. n ) uuuu h
c167cs derivatives the register set users manual 23-5 v2.0, 2000-07 c1pcir ef02 h x C can1 port control and interrupt register xxxx h c1uarn efn2 h x C can1 upper arbitration reg. (msg. n ) uuuu h c1ugml ef08 h x C can1 upper global mask long uuuu h c1umlm ef0c h x C can1 upper mask of last message uuuu h c2btr ee04 h x C can2 bit timing register uuuu h c2csr ee00 h x C can2 control/status register xx01 h c2gms ee06 h x C can2 global mask short ufuu h c2larn een4 h x C can2 lower arbitration register (msg. n ) uuuu h c2lgml ee0a h x C can2 lower global mask long uuuu h c2lmlm ee0e h x C can2 lower mask of last message uuuu h c2mcfgn een6 h x C can2 message configuration register (msg. n ) uu h c2mcrn een0 h x C can2 message ctrl. reg. (msg. n ) uuuu h c2pcir ee02 h x C can2port control and interrupt register xxxx h c2uarn een2 h x C can2 upper arbitration reg. (msg. n ) uuuu h c2ugml ee08 h x C can2 upper global mask long uuuu h c2umlm ee0c h x C can2 upper mask of last message uuuu h caprel fe4a h 25 h gpt2 capture/reload register 0000 h cc0 fe80 h 40 h capcom register 0 0000 h cc0ic b ff78 h bc h capcom register 0 interrupt ctrl. reg. 0000 h cc1 fe82 h 41 h capcom register 1 0000 h cc10 fe94 h 4a h capcom register 10 0000 h cc10ic b ff8c h c6 h capcom register 10 interrupt ctrl. reg. 0000 h cc11 fe96 h 4b h capcom register 11 0000 h cc11ic b ff8e h c7 h capcom register 11 interrupt ctrl. reg. 0000 h cc12 fe98 h 4c h capcom register 12 0000 h cc12ic b ff90 h c8 h capcom register 12 interrupt ctrl. reg. 0000 h cc13 fe9a h 4d h capcom register 13 0000 h cc13ic b ff92 h c9 h capcom register 13 interrupt ctrl. reg. 0000 h cc14 fe9c h 4e h capcom register 14 0000 h table 23-3 c167cs registers, ordered by name (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-6 v2.0, 2000-07 cc14ic b ff94 h ca h capcom register 14 interrupt ctrl. reg. 0000 h cc15 fe9e h 4f h capcom register 15 0000 h cc15ic b ff96 h cb h capcom register 15 interrupt ctrl. reg. 0000 h cc16 fe60 h 30 h capcom register 16 0000 h cc16ic b f160 h e b0 h capcom register 16 interrupt ctrl. reg. 0000 h cc17 fe62 h 31 h capcom register 17 0000 h cc17ic b f162 h e b1 h capcom register 17 interrupt ctrl. reg. 0000 h cc18 fe64 h 32 h capcom register 18 0000 h cc18ic b f164 h e b2 h capcom register 18 interrupt ctrl. reg. 0000 h cc19 fe66 h 33 h capcom register 19 0000 h cc19ic b f166 h e b3 h capcom register 19 interrupt ctrl. reg. 0000 h cc1ic b ff7a h bd h capcom register 1 interrupt ctrl. reg. 0000 h cc2 fe84 h 42 h capcom register 2 0000 h cc20 fe68 h 34 h capcom register 20 0000 h cc20ic b f168 h e b4 h capcom register 20 interrupt ctrl. reg. 0000 h cc21 fe6a h 35 h capcom register 21 0000 h cc21ic b f16a h e b5 h capcom register 21 interrupt ctrl. reg. 0000 h cc22 fe6c h 36 h capcom register 22 0000 h cc22ic b f16c h e b6 h capcom register 22 interrupt ctrl. reg. 0000 h cc23 fe6e h 37 h capcom register 23 0000 h cc23ic b f16e h e b7 h capcom register 23 interrupt ctrl. reg. 0000 h cc24 fe70 h 38 h capcom register 24 0000 h cc24ic b f170 h e b8 h capcom register 24 interrupt ctrl. reg. 0000 h cc25 fe72 h 39 h capcom register 25 0000 h cc25ic b f172 h e b9 h capcom register 25 interrupt ctrl. reg. 0000 h cc26 fe74 h 3a h capcom register 26 0000 h cc26ic b f174 h e ba h capcom register 26 interrupt ctrl. reg. 0000 h cc27 fe76 h 3b h capcom register 27 0000 h cc27ic b f176 h e bb h capcom register 27 interrupt ctrl. reg. 0000 h cc28 fe78 h 3c h capcom register 28 0000 h table 23-3 c167cs registers, ordered by name (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-7 v2.0, 2000-07 cc28ic b f178 h e bc h capcom register 28 interrupt ctrl. reg. 0000 h cc29 fe7a h 3d h capcom register 29 0000 h cc29ic b f184 h e c2 h capcom register 29 interrupt ctrl. reg. 0000 h cc2ic b ff7c h be h capcom register 2 interrupt ctrl. reg. 0000 h cc3 fe86 h 43 h capcom register 3 0000 h cc30 fe7c h 3e h capcom register 30 0000 h cc30ic b f18c h e c6 h capcom register 30 interrupt ctrl. reg. 0000 h cc31 fe7e h 3f h capcom register 31 0000 h cc31ic b f194 h e ca h capcom register 31 interrupt ctrl. reg. 0000 h cc3ic b ff7e h bf h capcom register 3 interrupt ctrl. reg. 0000 h cc4 fe88 h 44 h capcom register 4 0000 h cc4ic b ff80 h c0 h capcom register 4 interrupt ctrl. reg. 0000 h cc5 fe8a h 45 h capcom register 5 0000 h cc5ic b ff82 h c1 h capcom register 5 interrupt ctrl. reg. 0000 h cc6 fe8c h 46 h capcom register 6 0000 h cc6ic b ff84 h c2 h capcom register 6 interrupt ctrl. reg. 0000 h cc7 fe8e h 47 h capcom register 7 0000 h cc7ic b ff86 h c3 h capcom register 7 interrupt ctrl. reg. 0000 h cc8 fe90 h 48 h capcom register 8 0000 h cc8ic b ff88 h c4 h capcom register 8 interrupt ctrl. reg. 0000 h cc9 fe92 h 49 h capcom register 9 0000 h cc9ic b ff8a h c5 h capcom register 9 interrupt ctrl. reg. 0000 h ccm0 b ff52 h a9 h capcom mode control register 0 0000 h ccm1 b ff54 h aa h capcom mode control register 1 0000 h ccm2 b ff56 h ab h capcom mode control register 2 0000 h ccm3 b ff58 h ac h capcom mode control register 3 0000 h ccm4 b ff22 h 91 h capcom mode control register 4 0000 h ccm5 b ff24 h 92 h capcom mode control register 5 0000 h ccm6 b ff26 h 93 h capcom mode control register 6 0000 h ccm7 b ff28 h 94 h capcom mode control register 7 0000 h table 23-3 c167cs registers, ordered by name (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-8 v2.0, 2000-07 cp fe10 h 08 h cpu context pointer register fc00 h cric b ff6a h b5 h gpt2 caprel interrupt control register 0000 h csp fe08 h 04 h cpu code segment pointer register (8 bits, not directly writeable) 0000 h dp0h b f102 h e 81 h p0h direction control register 00 h dp0l b f100 h e 80 h p0l direction control register 00 h dp1h b f106 h e 83 h p1h direction control register 00 h dp1l b f104 h e 82 h p1l direction control register 00 h dp2 b ffc2 h e1 h port 2 direction control register 0000 h dp3 b ffc6 h e3 h port 3 direction control register 0000 h dp4 b ffca h e5 h port 4 direction control register 00 h dp6 b ffce h e7 h port 6 direction control register 00 h dp7 b ffd2 h e9 h port 7 direction control register 00 h dp8 b ffd6 h eb h port 8 direction control register 00 h dpp0 fe00 h 00 h cpu data page pointer 0 register (10 bits) 0000 h dpp1 fe02 h 01 h cpu data page pointer 1 register (10 bits) 0001 h dpp2 fe04 h 02 h cpu data page pointer 2 register (10 bits) 0002 h dpp3 fe06 h 03 h cpu data page pointer 3 register (10 bits) 0003 h exicon b f1c0 h e e0 h external interrupt control register 0000 h exisel b f1da h e ed h external interrupt source select register 0000 h focon b ffaa h d5 h frequency output control register 0000 h idchip f07c h e 3e h identifier 0cxx h idmanuf f07e h e 3f h identifier 1820 h idmem f07a h e 3d h identifier 3040 h idmem2 f076 h e 3b h identifier 5001 h idprog f078 h e 3c h identifier 4040 h isnc b f1de h e ef h interrupt subnode control register 0000 h mdc b ff0e h 87 h cpu multiply divide control register 0000 h mdh fe0c h 06 h cpu multiply divide register C high word 0000 h mdl fe0e h 07 h cpu multiply divide register C low word 0000 h table 23-3 c167cs registers, ordered by name (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-9 v2.0, 2000-07 odp2 b f1c2 h e e1 h port 2 open drain control register 0000 h odp3 b f1c6 h e e3 h port 3 open drain control register 0000 h odp4 b f1ca h e e5 h port 4 open drain control register 00 h odp6 b f1ce h e e7 h port 6 open drain control register 00 h odp7 b f1d2 h e e9 h port 7 open drain control register 00 h odp8 b f1d6 h e eb h port 8 open drain control register 00 h ones b ff1e h 8f h constant value 1s register (read only) ffff h p0h b ff02 h 81 h port 0 high register (upper half of port0) 00 h p0l b ff00 h 80 h port 0 low register (lower half of port0) 00 h p1didis fea4 h 52 h port1 digital input disable register 0000 h p1h b ff06 h 83 h port 1 high register (upper half of port1) 00 h p1l b ff04 h 82 h port 1 low register (lower half of port1) 00 h p2 b ffc0 h e0 h port 2 register 0000 h p3 b ffc4 h e2 h port 3 register 0000 h p4 b ffc8 h e4 h port 4 register (7 bits) 00 h p5 b ffa2 h d1 h port 5 register (read only) xxxx h p5didis b ffa4 h d2 h port 5 digital input disable register 0000 h p6 b ffcc h e6 h port 6 register (8 bits) 00 h p7 b ffd0 h e8 h port 7 register (8 bits) 00 h p8 b ffd4 h ea h port 8 register (8 bits) 00 h pecc0 fec0 h 60 h pec channel 0 control register 0000 h pecc1 fec2 h 61 h pec channel 1 control register 0000 h pecc2 fec4 h 62 h pec channel 2 control register 0000 h pecc3 fec6 h 63 h pec channel 3 control register 0000 h pecc4 fec8 h 64 h pec channel 4 control register 0000 h pecc5 feca h 65 h pec channel 5 control register 0000 h pecc6 fecc h 66 h pec channel 6 control register 0000 h pecc7 fece h 67 h pec channel 7 control register 0000 h picon f1c4 h e e2 h port input threshold control register 0000 h pocon0h f082 h e 41 h port p0h output control register 0000 h table 23-3 c167cs registers, ordered by name (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-10 v2.0, 2000-07 pocon0l f080 h e 40 h port p0l output control register 0000 h pocon1h f086 h e 43 h port p1h output control register 0000 h pocon1l f084 h e 42 h port p1l output control register 0000 h pocon2 f088 h e 44 h port p2 output control register 0000 h pocon20 f0aa h e 55 h dedicated pin output control register 0000 h pocon3 f08a h e 45 h port p3 output control register 0000 h pocon4 f08c h e 46 h port p4 output control register 0000 h pocon6 f08e h e 47 h port p6 output control register 0000 h pocon7 f090 h e 48 h port p7 output control register 0000 h pocon8 f092 h e 49 h port p8 output control register 0000 h pp0 f038 h e 1c h pwm module period register 0 0000 h pp1 f03a h e 1d h pwm module period register 1 0000 h pp2 f03c h e 1e h pwm module period register 2 0000 h pp3 f03e h e 1f h pwm module period register 3 0000 h psw b ff10 h 88 h cpu program status word 0000 h pt0 f030 h e 18 h pwm module up/down counter 0 0000 h pt1 f032 h e 19 h pwm module up/down counter 1 0000 h pt2 f034 h e 1a h pwm module up/down counter 2 0000 h pt3 f036 h e 1b h pwm module up/down counter 3 0000 h pw0 fe30 h 18 h pwm module pulse width register 0 0000 h pw1 fe32 h 19 h pwm module pulse width register 1 0000 h pw2 fe34 h 1a h pwm module pulse width register 2 0000 h pw3 fe36 h 1b h pwm module pulse width register 3 0000 h pwmcon0b ff30 h 98 h pwm module control register 0 0000 h pwmcon1b ff32 h 99 h pwm module control register 1 0000 h pwmic b f17e h e bf h pwm module interrupt control register 0000 h rp0h b f108 h e 84 h system startup configuration register (read only) xx h rstcon b f1e0 h m --- reset control register 00xx h rtch f0d6 h e 6b h rtc high register xxxx h table 23-3 c167cs registers, ordered by name (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-11 v2.0, 2000-07 rtcl f0d4 h e 6a h rtc low register xxxx h s0bg feb4 h 5a h serial channel 0 baud rate generator reload register 0000 h s0con b ffb0 h d8 h serial channel 0 control register 0000 h s0eic b ff70 h b8 h serial channel 0 error interrupt control register 0000 h s0rbuf feb2 h 59 h serial channel 0 receive buffer register (read only) xxxx h s0ric b ff6e h b7 h serial channel 0 receive interrupt control register 0000 h s0tbic b f19c h e ce h serial channel 0 transmit buffer interrupt control register 0000 h s0tbuf feb0 h 58 h serial channel 0 transmit buffer register 0000 h s0tic b ff6c h b6 h serial channel 0 transmit interrupt control register 0000 h sp fe12 h 09 h cpu system stack pointer register fc00 h sscbr f0b4 h e 5a h ssc baudrate register 0000 h ssccon b ffb2 h d9 h ssc control register 0000 h ssceic b ff76 h bb h ssc error interrupt control register 0000 h sscrb f0b2 h e 59 h ssc receive buffer xxxx h sscric b ff74 h ba h ssc receive interrupt control register 0000 h ssctb f0b0 h e 58 h ssc transmit buffer 0000 h ssctic b ff72 h b9 h ssc transmit interrupt control register 0000 h stkov fe14 h 0a h cpu stack overflow pointer register fa00 h stkun fe16 h 0b h cpu stack underflow pointer register fc00 h syscon b ff12 h 89 h cpu system configuration register 1) 0xx0 h syscon1 b f1dc h e ee h cpu system configuration register 1 0000 h syscon2 b f1d0 h e e8 h cpu system configuration register 2 0000 h syscon3 b f1d4 h e ea h cpu system configuration register 3 0000 h t0 fe50 h 28 h capcom timer 0 register 0000 h t01con b ff50 h a8 h capcom timer 0 and timer 1 ctrl. reg. 0000 h table 23-3 c167cs registers, ordered by name (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-12 v2.0, 2000-07 t0ic b ff9c h ce h capcom timer 0 interrupt ctrl. reg. 0000 h t0rel fe54 h 2a h capcom timer 0 reload register 0000 h t1 fe52 h 29 h capcom timer 1 register 0000 h t14 f0d2 h e 69 h rtc timer 14 register xxxx h t14rel f0d0 h e 68 h rtc timer 14 reload register xxxx h t1ic b ff9e h cf h capcom timer 1 interrupt ctrl. reg. 0000 h t1rel fe56 h 2b h capcom timer 1 reload register 0000 h t2 fe40 h 20 h gpt1 timer 2 register 0000 h t2con b ff40 h a0 h gpt1 timer 2 control register 0000 h t2ic b ff60 h b0 h gpt1 timer 2 interrupt control register 0000 h t3 fe42 h 21 h gpt1 timer 3 register 0000 h t3con b ff42 h a1 h gpt1 timer 3 control register 0000 h t3ic b ff62 h b1 h gpt1 timer 3 interrupt control register 0000 h t4 fe44 h 22 h gpt1 timer 4 register 0000 h t4con b ff44 h a2 h gpt1 timer 4 control register 0000 h t4ic b ff64 h b2 h gpt1 timer 4 interrupt control register 0000 h t5 fe46 h 23 h gpt2 timer 5 register 0000 h t5con b ff46 h a3 h gpt2 timer 5 control register 0000 h t5ic b ff66 h b3 h gpt2 timer 5 interrupt control register 0000 h t6 fe48 h 24 h gpt2 timer 6 register 0000 h t6con b ff48 h a4 h gpt2 timer 6 control register 0000 h t6ic b ff68 h b4 h gpt2 timer 6 interrupt control register 0000 h t7 f050 h e 28 h capcom timer 7 register 0000 h t78con b ff20 h 90 h capcom timer 7 and 8 control register 0000 h t7ic b f17a h e bd h capcom timer 7 interrupt ctrl. reg. 0000 h t7rel f054 h e 2a h capcom timer 7 reload register 0000 h t8 f052 h e 29 h capcom timer 8 register 0000 h t8ic b f17c h e be h capcom timer 8 interrupt ctrl. reg. 0000 h t8rel f056 h e 2b h capcom timer 8 reload register 0000 h tfr b ffac h d6 h trap flag register 0000 h table 23-3 c167cs registers, ordered by name (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-13 v2.0, 2000-07 wdt feae h 57 h watchdog timer register (read only) 0000 h wdtcon b ffae h d7 h watchdog timer control register 2) 00xx h xp0ic b f186 h e c3 h can1 interrupt control register 0000 h xp1ic b f18e h e c7 h can2 interrupt control register 0000 h xp2ic b f196 h e cb h unassigned interrupt control register 0000 h xp3ic b f19e h e cf h rtc/pll/owd interrupt control register 0000 h xpercon f024 h 12 h x-peripheral control register 0401 h zeros b ff1c h 8e h constant value 0s register (read only) 0000 h 1) the system configuration is selected during reset. 2) the reset value depends on the indicated reset source. table 23-3 c167cs registers, ordered by name (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-14 v2.0, 2000-07 23.4 special function registers ordered by address table 23-4 lists all sfrs which are implemented in the c167cs ordered by their physical address. bit-addressable sfrs are marked with the letter b in column name. sfrs within the extended sfr-space (esfrs) are marked with the letter e in column physical address. registers within on-chip x-peripherals are marked with the letter x in column physical address. table 23-4 c167cs registers, ordered by address name physical address 8-bit addr. description reset value c2csr ee00 h x C can2 control/status register xx01 h c2pcir ee02 h x C can2port control and interrupt register xxxx h c2btr ee04 h x C can2 bit timing register uuuu h c2gms ee06 h x C can2 global mask short ufuu h c2ugml ee08 h x C can2 upper global mask long uuuu h c2lgml ee0a h x C can2 lower global mask long uuuu h c2umlm ee0c h x C can2 upper mask of last message uuuu h c2lmlm ee0e h x C can2 lower mask of last message uuuu h c2mcrn een0 h x C can2 message ctrl. reg. (msg. n ) uuuu h c2uarn een2 h x C can2 upper arbitration reg. (msg. n ) uuuu h c2larn een4 h x C can2 lower arbitration register (msg. n ) uuuu h c2mcfgn een6 h x C can2 message configuration register (msg. n ) uu h c1csr ef00 h x C can1 control/status register xx01 h c1pcir ef02 h x C can1 port control and interrupt register xxxx h c1btr ef04 h x C can1 bit timing register uuuu h c1gms ef06 h x C can1 global mask short ufuu h c1ugml ef08 h x C can1 upper global mask long uuuu h c1lgml ef0a h x C can1 lower global mask long uuuu h c1umlm ef0c h x C can1 upper mask of last message uuuu h c1lmlm ef0e h x C can1 lower mask of last message uuuu h c1mcrn efn0 h x C can1 message ctrl. reg. (msg. n ) uuuu h c1uarn efn2 h x C can1 upper arbitration reg. (msg. n ) uuuu h
c167cs derivatives the register set users manual 23-15 v2.0, 2000-07 c1larn efn4 h x C can1 lower arbitration register (msg. n ) uuuu h c1mcfgn efn6 h x C can1 message configuration register (msg. n ) uu h xpercon f024 h 12 h x-peripheral control register 0401 h pt0 f030 h e 18 h pwm module up/down counter 0 0000 h pt1 f032 h e 19 h pwm module up/down counter 1 0000 h pt2 f034 h e 1a h pwm module up/down counter 2 0000 h pt3 f036 h e 1b h pwm module up/down counter 3 0000 h pp0 f038 h e 1c h pwm module period register 0 0000 h pp1 f03a h e 1d h pwm module period register 1 0000 h pp2 f03c h e 1e h pwm module period register 2 0000 h pp3 f03e h e 1f h pwm module period register 3 0000 h t7 f050 h e 28 h capcom timer 7 register 0000 h t8 f052 h e 29 h capcom timer 8 register 0000 h t7rel f054 h e 2a h capcom timer 7 reload register 0000 h t8rel f056 h e 2b h capcom timer 8 reload register 0000 h idmem2 f076 h e 3b h identifier 5001 h idprog f078 h e 3c h identifier 4040 h idmem f07a h e 3d h identifier 3040 h idchip f07c h e 3e h identifier 0cxx h idmanuf f07e h e 3f h identifier 1820 h pocon0l f080 h e 40 h port p0l output control register 0000 h pocon0h f082 h e 41 h port p0h output control register 0000 h pocon1l f084 h e 42 h port p1l output control register 0000 h pocon1h f086 h e 43 h port p1h output control register 0000 h pocon2 f088 h e 44 h port p2 output control register 0000 h pocon3 f08a h e 45 h port p3 output control register 0000 h pocon4 f08c h e 46 h port p4 output control register 0000 h pocon6 f08e h e 47 h port p6 output control register 0000 h pocon7 f090 h e 48 h port p7 output control register 0000 h table 23-4 c167cs registers, ordered by address (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-16 v2.0, 2000-07 pocon8 f092 h e 49 h port p8 output control register 0000 h addat2 f0a0 h e 50 h a/d converter 2 result register 0000 h pocon20 f0aa h e 55 h dedicated pin output control register 0000 h ssctb f0b0 h e 58 h ssc transmit buffer 0000 h sscrb f0b2 h e 59 h ssc receive buffer xxxx h sscbr f0b4 h e 5a h ssc baudrate register 0000 h t14rel f0d0 h e 68 h rtc timer 14 reload register xxxx h t14 f0d2 h e 69 h rtc timer 14 register xxxx h rtcl f0d4 h e 6a h rtc low register xxxx h rtch f0d6 h e 6b h rtc high register xxxx h dp0l b f100 h e 80 h p0l direction control register 00 h dp0h b f102 h e 81 h p0h direction control register 00 h dp1l b f104 h e 82 h p1l direction control register 00 h dp1h b f106 h e 83 h p1h direction control register 00 h rp0h b f108 h e 84 h system startup configuration register (read only) xx h cc16ic b f160 h e b0 h capcom register 16 interrupt ctrl. reg. 0000 h cc17ic b f162 h e b1 h capcom register 17 interrupt ctrl. reg. 0000 h cc18ic b f164 h e b2 h capcom register 18 interrupt ctrl. reg. 0000 h cc19ic b f166 h e b3 h capcom register 19 interrupt ctrl. reg. 0000 h cc20ic b f168 h e b4 h capcom register 20 interrupt ctrl. reg. 0000 h cc21ic b f16a h e b5 h capcom register 21 interrupt ctrl. reg. 0000 h cc22ic b f16c h e b6 h capcom register 22 interrupt ctrl. reg. 0000 h cc23ic b f16e h e b7 h capcom register 23 interrupt ctrl. reg. 0000 h cc24ic b f170 h e b8 h capcom register 24 interrupt ctrl. reg. 0000 h cc25ic b f172 h e b9 h capcom register 25 interrupt ctrl. reg. 0000 h cc26ic b f174 h e ba h capcom register 26 interrupt ctrl. reg. 0000 h cc27ic b f176 h e bb h capcom register 27 interrupt ctrl. reg. 0000 h cc28ic b f178 h e bc h capcom register 28 interrupt ctrl. reg. 0000 h t7ic b f17a h e bd h capcom timer 7 interrupt ctrl. reg. 0000 h table 23-4 c167cs registers, ordered by address (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-17 v2.0, 2000-07 t8ic b f17c h e be h capcom timer 8 interrupt ctrl. reg. 0000 h pwmic b f17e h e bf h pwm module interrupt control register 0000 h cc29ic b f184 h e c2 h capcom register 29 interrupt ctrl. reg. 0000 h xp0ic b f186 h e c3 h can1 interrupt control register 0000 h cc30ic b f18c h e c6 h capcom register 30 interrupt ctrl. reg. 0000 h xp1ic b f18e h e c7 h can2 interrupt control register 0000 h cc31ic b f194 h e ca h capcom register 31 interrupt ctrl. reg. 0000 h xp2ic b f196 h e cb h unassigned interrupt control register 0000 h s0tbic b f19c h e ce h serial channel 0 transmit buffer interrupt control register 0000 h xp3ic b f19e h e cf h rtc/pll/owd interrupt control register 0000 h exicon b f1c0 h e e0 h external interrupt control register 0000 h odp2 b f1c2 h e e1 h port 2 open drain control register 0000 h picon f1c4 h e e2 h port input threshold control register 0000 h odp3 b f1c6 h e e3 h port 3 open drain control register 0000 h odp4 b f1ca h e e5 h port 4 open drain control register 00 h odp6 b f1ce h e e7 h port 6 open drain control register 00 h syscon2 b f1d0 h e e8 h cpu system configuration register 2 0000 h odp7 b f1d2 h e e9 h port 7 open drain control register 00 h syscon3 b f1d4 h e ea h cpu system configuration register 3 0000 h odp8 b f1d6 h e eb h port 8 open drain control register 00 h exisel b f1da h e ed h external interrupt source select register 0000 h syscon1 b f1dc h e ee h cpu system configuration register 1 0000 h isnc b f1de h e ef h interrupt subnode control register 0000 h rstcon b f1e0 h m --- reset control register 00xx h dpp0 fe00 h 00 h cpu data page pointer 0 register (10 bits) 0000 h dpp1 fe02 h 01 h cpu data page pointer 1 register (10 bits) 0001 h dpp2 fe04 h 02 h cpu data page pointer 2 register (10 bits) 0002 h dpp3 fe06 h 03 h cpu data page pointer 3 register (10 bits) 0003 h table 23-4 c167cs registers, ordered by address (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-18 v2.0, 2000-07 csp fe08 h 04 h cpu code segment pointer register (8 bits, not directly writeable) 0000 h mdh fe0c h 06 h cpu multiply divide register C high word 0000 h mdl fe0e h 07 h cpu multiply divide register C low word 0000 h cp fe10 h 08 h cpu context pointer register fc00 h sp fe12 h 09 h cpu system stack pointer register fc00 h stkov fe14 h 0a h cpu stack overflow pointer register fa00 h stkun fe16 h 0b h cpu stack underflow pointer register fc00 h addrsel1 fe18 h 0c h address select register 1 0000 h addrsel2 fe1a h 0d h address select register 2 0000 h addrsel3 fe1c h 0e h address select register 3 0000 h addrsel4 fe1e h 0f h address select register 4 0000 h pw0 fe30 h 18 h pwm module pulse width register 0 0000 h pw1 fe32 h 19 h pwm module pulse width register 1 0000 h pw2 fe34 h 1a h pwm module pulse width register 2 0000 h pw3 fe36 h 1b h pwm module pulse width register 3 0000 h t2 fe40 h 20 h gpt1 timer 2 register 0000 h t3 fe42 h 21 h gpt1 timer 3 register 0000 h t4 fe44 h 22 h gpt1 timer 4 register 0000 h t5 fe46 h 23 h gpt2 timer 5 register 0000 h t6 fe48 h 24 h gpt2 timer 6 register 0000 h caprel fe4a h 25 h gpt2 capture/reload register 0000 h t0 fe50 h 28 h capcom timer 0 register 0000 h t1 fe52 h 29 h capcom timer 1 register 0000 h t0rel fe54 h 2a h capcom timer 0 reload register 0000 h t1rel fe56 h 2b h capcom timer 1 reload register 0000 h cc16 fe60 h 30 h capcom register 16 0000 h cc17 fe62 h 31 h capcom register 17 0000 h cc18 fe64 h 32 h capcom register 18 0000 h cc19 fe66 h 33 h capcom register 19 0000 h table 23-4 c167cs registers, ordered by address (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-19 v2.0, 2000-07 cc20 fe68 h 34 h capcom register 20 0000 h cc21 fe6a h 35 h capcom register 21 0000 h cc22 fe6c h 36 h capcom register 22 0000 h cc23 fe6e h 37 h capcom register 23 0000 h cc24 fe70 h 38 h capcom register 24 0000 h cc25 fe72 h 39 h capcom register 25 0000 h cc26 fe74 h 3a h capcom register 26 0000 h cc27 fe76 h 3b h capcom register 27 0000 h cc28 fe78 h 3c h capcom register 28 0000 h cc29 fe7a h 3d h capcom register 29 0000 h cc30 fe7c h 3e h capcom register 30 0000 h cc31 fe7e h 3f h capcom register 31 0000 h cc0 fe80 h 40 h capcom register 0 0000 h cc1 fe82 h 41 h capcom register 1 0000 h cc2 fe84 h 42 h capcom register 2 0000 h cc3 fe86 h 43 h capcom register 3 0000 h cc4 fe88 h 44 h capcom register 4 0000 h cc5 fe8a h 45 h capcom register 5 0000 h cc6 fe8c h 46 h capcom register 6 0000 h cc7 fe8e h 47 h capcom register 7 0000 h cc8 fe90 h 48 h capcom register 8 0000 h cc9 fe92 h 49 h capcom register 9 0000 h cc10 fe94 h 4a h capcom register 10 0000 h cc11 fe96 h 4b h capcom register 11 0000 h cc12 fe98 h 4c h capcom register 12 0000 h cc13 fe9a h 4d h capcom register 13 0000 h cc14 fe9c h 4e h capcom register 14 0000 h cc15 fe9e h 4f h capcom register 15 0000 h addat fea0 h 50 h a/d converter result register 0000 h p1didis fea4 h 52 h port1 digital input disable register 0000 h table 23-4 c167cs registers, ordered by address (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-20 v2.0, 2000-07 wdt feae h 57 h watchdog timer register (read only) 0000 h s0tbuf feb0 h 58 h serial channel 0 transmit buffer register 0000 h s0rbuf feb2 h 59 h serial channel 0 receive buffer register (read only) xxxx h s0bg feb4 h 5a h serial channel 0 baud rate generator reload register 0000 h pecc0 fec0 h 60 h pec channel 0 control register 0000 h pecc1 fec2 h 61 h pec channel 1 control register 0000 h pecc2 fec4 h 62 h pec channel 2 control register 0000 h pecc3 fec6 h 63 h pec channel 3 control register 0000 h pecc4 fec8 h 64 h pec channel 4 control register 0000 h pecc5 feca h 65 h pec channel 5 control register 0000 h pecc6 fecc h 66 h pec channel 6 control register 0000 h pecc7 fece h 67 h pec channel 7 control register 0000 h p0l b ff00 h 80 h port 0 low register (lower half of port0) 00 h p0h b ff02 h 81 h port 0 high register (upper half of port0) 00 h p1l b ff04 h 82 h port 1 low register (lower half of port1) 00 h p1h b ff06 h 83 h port 1 high register (upper half of port1) 00 h buscon0 b ff0c h 86 h bus configuration register 0 0000 h mdc b ff0e h 87 h cpu multiply divide control register 0000 h psw b ff10 h 88 h cpu program status word 0000 h syscon b ff12 h 89 h cpu system configuration register 1) 0xx0 h buscon1 b ff14 h 8a h bus configuration register 1 0000 h buscon2 b ff16 h 8b h bus configuration register 2 0000 h buscon3 b ff18 h 8c h bus configuration register 3 0000 h buscon4 b ff1a h 8d h bus configuration register 4 0000 h zeros b ff1c h 8e h constant value 0s register (read only) 0000 h ones b ff1e h 8f h constant value 1s register (read only) ffff h t78con b ff20 h 90 h capcom timer 7 and 8 control register 0000 h ccm4 b ff22 h 91 h capcom mode control register 4 0000 h table 23-4 c167cs registers, ordered by address (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-21 v2.0, 2000-07 ccm5 b ff24 h 92 h capcom mode control register 5 0000 h ccm6 b ff26 h 93 h capcom mode control register 6 0000 h ccm7 b ff28 h 94 h capcom mode control register 7 0000 h pwmcon0b ff30 h 98 h pwm module control register 0 0000 h pwmcon1b ff32 h 99 h pwm module control register 1 0000 h t2con b ff40 h a0 h gpt1 timer 2 control register 0000 h t3con b ff42 h a1 h gpt1 timer 3 control register 0000 h t4con b ff44 h a2 h gpt1 timer 4 control register 0000 h t5con b ff46 h a3 h gpt2 timer 5 control register 0000 h t6con b ff48 h a4 h gpt2 timer 6 control register 0000 h t01con b ff50 h a8 h capcom timer 0 and timer 1 ctrl. reg. 0000 h ccm0 b ff52 h a9 h capcom mode control register 0 0000 h ccm1 b ff54 h aa h capcom mode control register 1 0000 h ccm2 b ff56 h ab h capcom mode control register 2 0000 h ccm3 b ff58 h ac h capcom mode control register 3 0000 h t2ic b ff60 h b0 h gpt1 timer 2 interrupt control register 0000 h t3ic b ff62 h b1 h gpt1 timer 3 interrupt control register 0000 h t4ic b ff64 h b2 h gpt1 timer 4 interrupt control register 0000 h t5ic b ff66 h b3 h gpt2 timer 5 interrupt control register 0000 h t6ic b ff68 h b4 h gpt2 timer 6 interrupt control register 0000 h cric b ff6a h b5 h gpt2 caprel interrupt control register 0000 h s0tic b ff6c h b6 h serial channel 0 transmit interrupt control register 0000 h s0ric b ff6e h b7 h serial channel 0 receive interrupt control register 0000 h s0eic b ff70 h b8 h serial channel 0 error interrupt control register 0000 h ssctic b ff72 h b9 h ssc transmit interrupt control register 0000 h sscric b ff74 h ba h ssc receive interrupt control register 0000 h ssceic b ff76 h bb h ssc error interrupt control register 0000 h table 23-4 c167cs registers, ordered by address (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-22 v2.0, 2000-07 cc0ic b ff78 h bc h capcom register 0 interrupt ctrl. reg. 0000 h cc1ic b ff7a h bd h capcom register 1 interrupt ctrl. reg. 0000 h cc2ic b ff7c h be h capcom register 2 interrupt ctrl. reg. 0000 h cc3ic b ff7e h bf h capcom register 3 interrupt ctrl. reg. 0000 h cc4ic b ff80 h c0 h capcom register 4 interrupt ctrl. reg. 0000 h cc5ic b ff82 h c1 h capcom register 5 interrupt ctrl. reg. 0000 h cc6ic b ff84 h c2 h capcom register 6 interrupt ctrl. reg. 0000 h cc7ic b ff86 h c3 h capcom register 7 interrupt ctrl. reg. 0000 h cc8ic b ff88 h c4 h capcom register 8 interrupt ctrl. reg. 0000 h cc9ic b ff8a h c5 h capcom register 9 interrupt ctrl. reg. 0000 h cc10ic b ff8c h c6 h capcom register 10 interrupt ctrl. reg. 0000 h cc11ic b ff8e h c7 h capcom register 11 interrupt ctrl. reg. 0000 h cc12ic b ff90 h c8 h capcom register 12 interrupt ctrl. reg. 0000 h cc13ic b ff92 h c9 h capcom register 13 interrupt ctrl. reg. 0000 h cc14ic b ff94 h ca h capcom register 14 interrupt ctrl. reg. 0000 h cc15ic b ff96 h cb h capcom register 15 interrupt ctrl. reg. 0000 h adcic b ff98 h cc h a/d converter end of conversion interrupt control register 0000 h adeic b ff9a h cd h a/d converter overrun error interrupt control register 0000 h t0ic b ff9c h ce h capcom timer 0 interrupt ctrl. reg. 0000 h t1ic b ff9e h cf h capcom timer 1 interrupt ctrl. reg. 0000 h adcon b ffa0 h d0 h a/d converter control register 0000 h p5 b ffa2 h d1 h port 5 register (read only) xxxx h p5didis b ffa4 h d2 h port 5 digital input disable register 0000 h focon b ffaa h d5 h frequency output control register 0000 h tfr b ffac h d6 h trap flag register 0000 h wdtcon b ffae h d7 h watchdog timer control register 2) 00xx h s0con b ffb0 h d8 h serial channel 0 control register 0000 h ssccon b ffb2 h d9 h ssc control register 0000 h table 23-4 c167cs registers, ordered by address (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-23 v2.0, 2000-07 p2 b ffc0 h e0 h port 2 register 0000 h dp2 b ffc2 h e1 h port 2 direction control register 0000 h p3 b ffc4 h e2 h port 3 register 0000 h dp3 b ffc6 h e3 h port 3 direction control register 0000 h p4 b ffc8 h e4 h port 4 register (7 bits) 00 h dp4 b ffca h e5 h port 4 direction control register 00 h p6 b ffcc h e6 h port 6 register (8 bits) 00 h dp6 b ffce h e7 h port 6 direction control register 00 h p7 b ffd0 h e8 h port 7 register (8 bits) 00 h dp7 b ffd2 h e9 h port 7 direction control register 00 h p8 b ffd4 h ea h port 8 register (8 bits) 00 h dp8 b ffd6 h eb h port 8 direction control register 00 h 1) the system configuration is selected during reset. 2) the reset value depends on the indicated reset source. table 23-4 c167cs registers, ordered by address (contd) name physical address 8-bit addr. description reset value
c167cs derivatives the register set users manual 23-24 v2.0, 2000-07 23.5 special notes pec pointer registers the source and destination pointers for the peripheral event controller are mapped to a special area within the internal ram. pointers that are not occupied by the pec may therefore be used like normal ram. during power down mode or any warm reset the pec pointers are preserved. the pec and its registers are described in chapter 5 . gpr access in the esfr area the locations 00f000 h 00f01e h within the esfr area are reserved and allow to access the current register bank via short register addressing modes. the gprs are mirrored to the esfr area which allows access to the current register bank even after switching register spaces (see example below). mov r5, dp3 ;gpr access via sfr area extr #1 mov r5, odp3 ;gpr access via esfr area writing bytes to sfrs all special function registers may be accessed wordwise or bytewise (some of them even bitwise). reading bytes from word sfrs is a non-critical operation. however, when writing bytes to word sfrs the complementary byte of the respective sfr is cleared with the write operation.
c167cs derivatives instruction set summary users manual 24-1 v2.0, 2000-07 24 instruction set summary this chapter briefly summarizes the c167cs s instructions ordered by instruction classes. this provides a basic understanding of the c167css instruction set, the power and versatility of the instructions and their general usage. a detailed description of each single instruction, including its operand data type, condition flag settings, addressing modes, length (number of bytes) and object code format is provided in the instruction set manual for the c166 family. this manual also provides tables ordering the instructions according to various criteria, to allow quick references. summary of instruction classes grouping the various instruction into classes aids in identifying similar instructions (e.g. shr, ror) and variations of certain instructions (e.g. add, addb). this provides an easy access to the possibilities and the power of the instructions of the c167cs. note: the used mnemonics refer to the detailed description. arithmetic instructions ? addition of two words or bytes: add addb ? addition with carry of two words or bytes: addc addcb ? subtraction of two words or bytes: sub subb ? subtraction with carry of two words or bytes: subc subcb ?16 16 bit signed or unsigned multiplication: mul mulu ? 16 / 16 bit signed or unsigned division: div divu ? 32 / 16 bit signed or unsigned division: divl divlu ? 1s complement of a word or byte: cpl cplb ? 2s complement (negation) of a word or byte: neg negb logical instructions ? bitwise anding of two words or bytes: and andb ? bitwise oring of two words or bytes: or orb ? bitwise xoring of two words or bytes: xor xorb compare and loop control instructions ? comparison of two words or bytes: cmp cmpb ? comparison of two words with post-increment by either 1 or 2: cmpi1 cmpi2 ? comparison of two words with post-decrement by either 1 or 2: cmpd1 cmpd2
c167cs derivatives instruction set summary users manual 24-2 v2.0, 2000-07 boolean bit manipulation instructions ? manipulation of a maskable bit field in either the high or the low byte of a word: bfldh bfldl ? setting a single bit (to 1): bset ? clearing a single bit (to 0): bclr ? movement of a single bit: bmov ? movement of a negated bit: bmovn ? anding of two bits: band ? oring of two bits: bor ? xoring of two bits: bxor ? comparison of two bits: bcmp shift and rotate instructions ? shifting right of a word: shr ? shifting left of a word: shl ? rotating right of a word: ror ? rotating left of a word: rol ? arithmetic shifting right of a word (sign bit shifting): ashr prioritize instruction ? determination of the number of shift cycles required to normalize a word operand (floating point support): prior data movement instructions ? standard data movement of a word or byte: mov movb ? data movement of a byte to a word location with either sign or zero byte extension: movbs movbz note: the data movement instructions can be used with a big number of different addressing modes including indirect addressing and automatic pointer in-/ decrementing. system stack instructions ? pushing of a word onto the system stack: push ? popping of a word from the system stack: pop ? saving of a word on the system stack, and then updating the old word with a new value (provided for register bank switching): scxt
c167cs derivatives instruction set summary users manual 24-3 v2.0, 2000-07 jump instructions ? conditional jumping to an either absolutely, indirectly, or relatively addressed target instruction within the current code segment: jmpa jmpi jmpr ? unconditional jumping to an absolutely addressed target instruction within any code segment: jmps ? conditional jumping to a relatively addressed target instruction within the current code segment depending on the state of a selectable bit: jb jnb ? conditional jumping to a relatively addressed target instruction within the current code segment depending on the state of a selectable bit with a post-inversion of the tested bit in case of jump taken (semaphore support): jbc jnbs call instructions ? conditional calling of an either absolutely or indirectly addressed subroutine within the current code segment: calla calli ? unconditional calling of a relatively addressed subroutine within the current code segment: callr ? unconditional calling of an absolutely addressed subroutine within any code segment: calls ? unconditional calling of an absolutely addressed subroutine within the current code segment plus an additional pushing of a selectable register onto the system stack: pcall ? unconditional branching to the interrupt or trap vector jump table in code segment 0: trap return instructions ? returning from a subroutine within the current code segment: ret ? returning from a subroutine within any code segment: rets ? returning from a subroutine within the current code segment plus an additional popping of a selectable register from the system stack: retp ? returning from an interrupt service routine: reti
c167cs derivatives instruction set summary users manual 24-4 v2.0, 2000-07 system control instructions ? resetting the c167cs via software: srst ? entering the idle mode: idle ? entering the power down mode: pwrdn ? servicing the watchdog timer: srvwdt ? disabling the watchdog timer: diswdt ? signifying the end of the initialization routine (pulls pin rstout high, and disables the effect of any later execution of a diswdt instruction): einit miscellaneous ? null operation which requires 2 bytes of storage and the minimum time for execution: nop ? definition of an unseparable instruction sequence: atomic ? switch reg, bitoff and bitaddr addressing modes to the extended sfr space: extr ? override the dpp addressing scheme using a specific data page instead of the dpps, and optionally switch to esfr space: extp extpr ? override the dpp addressing scheme using a specific segment instead of the dpps, and optionally switch to esfr space: exts extsr note: the atomic and ext* instructions provide support for uninterruptable code sequences e.g. for semaphore operations. they also support data addressing beyond the limits of the current dpps (except atomic), which is advantageous for bigger memory models in high level languages. refer to chapter 22 for examples. protected instructions some instructions of the c167cs which are critical for the functionality of the controller are implemented as so-called protected instructions. these protected instructions use the maximum instruction format of 32 bits for decoding, while the regular instructions only use a part of it (e.g. the lower 8 bits) with the other bits providing additional information like involved registers. decoding all 32 bits of a protected doubleword instruction increases the security in cases of data distortion during instruction fetching. critical operations like a software reset are therefore only executed if the complete instruction is decoded without an error. this enhances the safety and reliability of a microcontroller system.
c167cs derivatives device specification users manual 25-1 v2.0, 2000-07 25 device specification the device specification describes the electrical parameters of the device. it lists dc characteristics like input, output or supply voltages or currents, and ac characteristics like timing characteristics and requirements. other than the architecture, the instruction set or the basic functions of the c167cs core and its peripherals, these dc and ac characteristics are subject to changes due to device improvements or specific derivatives of the standard device. therefore these characteristics are not contained in this manual, but rather provided in a separate data sheet, which can be updated more frequently. please refer to the current version of the data sheet of the respective device for all electrical parameters. note: in any case the specific characteristics of a device should be verified, before a new design is started. this ensures that the used information is up to date. figure 25-1 shows the pin diagram of the c167cs. it shows the location of the different supply and io pins. a detailed description of all the pins is also found in the data sheet. note: not all alternate functions shown in the figure below are supported by all derivatives. please refer to the corresponding descriptions in the data sheets.
c167cs derivatives device specification users manual 25-2 v2.0, 2000-07 figure 25-1 pin configuration p-mqfp-144 package (top view) note: signals can1_txd and can1_rxd are not available in all derivatives of the c167cs. 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 144 143 142 141 140 139 138 137 136 135 134 133 132 131 130 129 128 127 126 125 124 123 122 121 120 119 118 117 116 115 114 113 112 111 110 109 108 107 106 105 104 103 102 101 100 99 98 97 96 95 94 93 92 91 90 89 88 87 86 85 84 83 82 81 80 79 78 77 76 75 74 73 v aref v agnd p5.10/an10/t6eud p5.11/an11/t5eud p5.12/an12/t6in p5.13/an13/t5in p5.14/an14/t4eud p5.15/an15/t2eud v ss v dd p2.0/cc0io p2.1/cc1io p2.2/cc2io p2.3/cc3io p2.4/cc4io p2.5/cc5io p2.6/cc6io p2.7/cc7io v ss v dd p2.8/cc8io/ex0in p2.9/cc9io/ex1in p2.10/cc10io/ex2in p2.11/cc11io/ex3in p2.12/cc12io/ex4in p2.13/cc13io/ex5in p2.14/cc14io/ex6in p2.15/cc15io/ex7in/t7in p3.0/t0in p3.1/t6out p3.2/capin p3.3/t3out p3.4/t3eud p3.5/t4in v ss v dd v dd v ss nmi rstout rstin v ss xtal1 xtal2 v dd p1h.7/a15/cc27io p1h.6/a14/cc26io p1h.5/a13/cc25io p1h.4/a12/cc24io p1h.3/a11 p1h.2/a10 p1h.1/a9 p1h.0/a8 v ss v dd p1l.7/a7/an23 p1l.6/a6/an22 p1l.5/a5/an21 p1l.4/a4/an20 p1l.3/a3/an19 p1l.2/a2/an18 p1l.1/a1/an17 p1l.0/a0/an16 p0h.7/ad15 p0h.6/ad14 p0h.5/ad13 p0h.4/ad12 p0h.3/ad11 p0h.2/ad10 p0h.1/ad9 v ss v dd p0h.0/ad8 p0l.7/ad7 p0l.6/ad6 p0l.5/ad5 p0l.4/ad4 p0l.3/ad3 p0l.2/ad2 p0l.1/ad1 p0l.0/ad0 ea ale ready wr/wrl rd v ss v dd p4.7/a23/* p4.6/a22/* p4.5/a21/* p4.4/a20/* p4.3/a19 p4.2/a18 p4.1/a17 p4.0/a16 n.c. v ss v dd p3.15/clkout/fou t p3.13/sclk p3.12/bhe/wrh p3.111/rxd0 p3.10/txd0 p3.9/mtsr p3.8/mrst p3.7/t2in p3.6/t3in p6.0/cs0 p6.1/cs1 p6.2/cs2 p6.3/cs3 p6.4/cs4 p6.5/hold p6.6/hlda p6.7/breq *p8.0/cc16io *p8.1/cc17io *p8.2/cc18io *p8.3/cc19io p8.4/cc20io p8.5/cc21io p8.6/cc22io p8.7/cc23io v dd v ss p7.0/pout0 p7.1/pout1 p7.2/pout2 p7.3/pout3 p7.4/cc28io p7.5/cc29io p7.6/cc30io p7.7/cc31io p5.0/an0 p5.1/an1 p5.2/an2 p5.3/an3 p5.4/an4 p5.5/an5 p5.6/an6 p5.7/an7 p5.8/an8 p5.9/an9 c167cs mcp04431
c167cs derivatives keyword index users manual 26-1 v2.0, 2000-07 a access to x-peripherals 9-40 acronyms 1-7 adapt mode 20-15 adc 2-15, 18-1 adcic, adeic 18-15 adcon 18-3 addat, addat2 18-6 address arbitration 9-27 area definition 9-26 boundaries 3-12 segment 9-9, 20-18 addrselx 9-25, 9-27 ale length 9-13 alternate signals 7-9 alu 4-16 analog/digital converter 2-15, 18-1 arbitration address 9-27 external bus 9-31 master/slave mode 9-35 signals 9-32 asc0 11-1 asynchronous mode 11-5 baudrate 11-11 error detection 11-10 interrupts 11-15 synchronous mode 11-8 asynchronous serial interface (->asc0) 11-1 auto scan conversion 18-7 b baudrate asc0 11-11 bootstrap loader 15-6 ssc 12-13 bhe 7-31, 9-9 bidirectional reset 20-4 bit addressable memory 3-4 handling 4-10 manipulation instructions 24-2 protected 2-19, 4-10 reserved 2-12 bootstrap loader 15-1, 20-16 boundaries 3-12 btr 19-13 burst mode (pwm) 17-7 bus arbitration 9-31 can 2-14, 19-1, 19-38 demultiplexed 9-5 idle state 9-30 mode configuration 9-3, 20-17 multiplexed 9-4 busconx 9-22, 9-27 c can interface 2-14, 19-1 activation 19-32 port control 19-40 second 19-37 capcom 2-17 interrupt 16-22 timer 16-4 unit 16-1 capture mode capcom 16-13 gpt1 10-20 26 keyword index this section lists a number of keywords which refer to specific details of the c167cs in terms of its architecture, its functional units or functions. this helps to quickly find the answer to specific questions about the c167cs.
c167cs derivatives keyword index users manual 26-2 v2.0, 2000-07 gpt2 (caprel) 10-34 capture/compare unit 16-1 ccm0, ccm1, ccm2, ccm3 16-10 ccm4, ccm5, ccm6, ccm7 16-11 ccxic 16-22 center aligned pwm 17-5 chip select configuration 9-10, 20-18 latched/early 9-11 clock distribution 6-1, 21-14 generator modes 6-7, 20-19 output signal 21-17 code memory handling 22-16 compare modes 16-14 double register 16-19 concatenation of timers 10-16, 10-33 configuration address 9-9, 20-18 bus mode 9-3, 20-17 chip select 9-10, 20-18 default 20-20 pll 6-7, 20-19 reset 20-7, 20-12 special modes 20-16 write control 20-17 context pointer 4-25 context switching 5-19 conversion analog/digital 18-1 auto scan 18-7 timing control 18-13 count direction 10-4, 10-25 counter 10-8, 10-14, 10-29, 10-31, 17-10 cp 4-25 cpu 2-2, 4-1 cric 10-38 csp 4-20 csr 19-8 d data page 4-22, 22-14 boundaries 3-12 default startup configuration 20-20 delay read/write 9-16 demultiplexed bus 9-5 development support 1-6 direct drive 6-6 direction count 10-4, 10-25 disable interrupt 5-16 peripheral 21-14 segmentation 4-15 division 4-30, 22-1 double-register compare 16-19 dp0l, dp0h 7-13 dp1l, dp1h 7-17 dp2 7-23 dp3 7-28 dp4 7-33, 7-42, 7-48 dp8 7-53 dpp 4-22, 22-14 driver characteristic (ports) 7-5 e early chip select 9-11 early wr control 9-16 edge aligned pwm 17-3 edge characteristic (ports) 7-6 emulation mode 20-14 enable interrupt 5-16 peripheral 21-14 segmentation 4-15 xbus peripherals 9-38 error detection asc0 11-10 can 19-5 ssc 12-15 exicon 5-28 exisel 5-29 external bus 2-10
c167cs derivatives keyword index users manual 26-3 v2.0, 2000-07 bus characteristics 9-12C9-19 bus idle state 9-30 bus modes 9-3C9-8 fast interrupts 5-28 host mode (->ehm) 20-16 interrupt source control 5-29 interrupts 5-26 interrupts during sleep mode 5-30 startup configuration 20-13 f fast external interrupts 5-28 flags 4-16C4-19 focon 21-18 frequency output signal 21-17 full duplex 12-7 g gms 19-16 gpr 3-6, 4-25, 23-2 gpt 2-16 gpt1 10-1 gpt2 10-22 h half duplex 12-10 hardware reset 20-2 traps 5-31 hold state entry 9-33 exit 9-34 i idle mode 21-3 state (bus) 9-30 incremental interface 10-9 indication of reset source 13-6 input threshold 7-2 instruction 22-1, 24-1 bit manipulation 24-2 branch 4-4 pipeline 4-3 protected 24-4 timing 4-11 unseparable 22-14 interface can 2-14, 19-1 external bus 9-1 serial async. (->asc0) 11-1 serial sync. (->ssc) 12-1 internal ram 3-4 interrupt capcom 16-22 during sleep mode 5-30 enable/disable 5-16 external 5-26 fast external 5-28 handling can 19-10 node sharing 5-25 priority 5-8 processing 5-1, 5-6 response times 5-20 rtc 14-3 source control 5-29 sources 5-2 system 2-7, 5-2 vectors 5-2 ip 4-19 iram 3-4 status after reset 20-8 isnc 5-25 l larn 19-22 latched chip select 9-11 lgml 19-17 lmlm 19-18 m management peripheral 21-14 power 21-1 master mode external bus 9-35
c167cs derivatives keyword index users manual 26-4 v2.0, 2000-07 mcfgn 19-23 mcrn 19-20 mdc 4-32 mdh 4-30 mdl 4-31 memory 2-8 bit-addressable 3-4 code memory handling 22-16 external 3-11 ram/sfr 3-4 rom area 3-3 tri-state time 9-15 xram 3-9 memory cycle time 9-14 multiplexed bus 9-4 multiplication 4-30, 22-1 n nmi 5-1, 5-34 noise filter (ext. interrupts) 5-30 o odp2 7-24, 7-43, 7-49 odp3 7-29 odp4 7-34 odp8 7-54 ones 4-33 open drain mode 7-4 oscillator circuitry 6-2 measurement 6-2 watchdog 6-8, 20-19 p p0l, p0h 7-12 p1dids 7-19 p1l, p1h 7-16 p2 7-23 p3 7-28 p4 7-33, 7-42, 7-48 p5 7-38 p5didis 7-40 p8 7-53 pcir 19-11 pec 2-8, 3-7, 5-12 response times 5-23 peccx 5-12 peripheral enable on xbus 9-38 enable/disable 21-14 management 21-14 summary 2-11 phase locked loop (->pll) 6-1 picon 7-2 pins 8-1, 25-2 in idle and power down mode 21-9 pipeline 4-3 effects 4-6 pll 6-1, 20-19 poconx 7-7 port 2-14 driver characteristic 7-5 edge characteristic 7-6 input threshold 7-2 power down mode 21-6 power management 2-18, 21-1 prescaler 6-6 protected bits 2-19, 4-10 instruction 24-4 psw 4-16, 5-10 pulse width modulation 2-17 pwm 2-17 pwm module 17-1 pwmcon0 17-12 pwmcon1 17-13 pwmic 17-14 r ram extension 3-9 internal 3-4 read/write delay 9-16 ready 9-18 real time clock (->rtc) 14-1 registers 23-1
c167cs derivatives keyword index users manual 26-5 v2.0, 2000-07 sorted by address 23-14 sorted by name 23-4 reserved bits 2-12 reset 20-1 bidirectional 20-4 configuration 20-7, 20-12 hardware 20-2 output 20-8 software 20-3 source indication 13-6 values 20-5 watchdog timer 20-3 rstcon 20-23 rtc 2-15, 14-1 s s0bg 11-11 s0con 11-2 s0eic, s0ric, s0tic, s0tbic 11-15 s0rbuf 11-7, 11-9 s0tbuf 11-7, 11-9 security mechanism 21-22 segment address 9-9, 20-18 boundaries 3-12 segmentation 4-20 enable/disable 4-15 serial interface 2-13, 11-1 asynchronous 11-5 can 2-14, 19-1 synchronous 11-8, 12-1 sfr 3-8, 23-4, 23-14 sharing x-peripherals 9-40 single chip mode 9-2 startup configuration 20-20 single shot mode (pwm) 17-8 slave mode external bus 9-35 sleep mode 21-5 slow down mode 21-10 software reset 20-3 system configuration 20-22 traps 5-31 source interrupt 5-2 reset 13-6 sp 4-27 special operation modes (config.) 20-16 ssc 12-1 baudrate generation 12-13 error detection 12-15 full duplex 12-7 half duplex 12-10 sscbr 12-13 ssccon 12-2, 12-4 ssceic, sscric, ssctic 12-17 sscrb, ssctb 12-8 stack 3-5, 4-27, 22-4 startup configuration 20-7, 20-12 external reset 20-13 single-chip 20-20 via software 20-22 stkov 4-28 stkun 4-29 subroutine 22-10 synchronous serial interface (->ssc) 12-1 syscon 4-13, 9-20 syscon1 21-6 syscon2 21-12 syscon3 21-15 t t01con 16-5 t2con 10-12 t2ic, t3ic, t4ic 10-21 t3con 10-3 t4con 10-12 t5con 10-30 t5ic, t6ic 10-38 t6con 10-24 t78con 16-5 t7ic 16-9 t8ic 16-9 tfr 5-33
c167cs derivatives keyword index users manual 26-6 v2.0, 2000-07 threshold 7-2 timer 2-16, 10-1, 10-22 auxiliary timer 10-12, 10-30 capcom 16-4 concatenation 10-16, 10-33 core timer 10-3, 10-24 tools 1-6 traps 5-31 tri-state time 9-15 u uarn 19-22 ugml 19-17 umlm 19-18 unlock sequence 21-22 unseparable instructions 22-14 v visible mode 9-39 w waitstate memory cycle 9-14 tri-state 9-15 xbus peripheral 9-38 watchdog 2-18, 13-1 after reset 20-5 oscillator 6-8, 20-19 reset 20-3 wdt 13-2 wdtcon 13-4 x xbus 2-10, 9-37 enable peripherals 9-38 external access 9-40 waitstates 9-38 xpercon 9-38 xper-share mode 9-40 xram on-chip 3-9 status after reset 20-8 xxic 5-7 z zeros 4-33
http://www.infineon.com published by infineon technologies ag infineon goes for business excellence business excellence means intelligent approaches and clearly defined processes, which are both constantly under review and ultimately lead to good operating results. better operating results and business excellence mean less idleness and wastefulness for all of us, more professional success, more accurate information, a better overview and, thereby, less frustration and more satisfaction. dr. ulrich schumacher


▲Up To Search▲   

 
Price & Availability of C167CS-LM

All Rights Reserved © IC-ON-LINE 2003 - 2022  

[Add Bookmark] [Contact Us] [Link exchange] [Privacy policy]
Mirror Sites :  [www.datasheet.hk]   [www.maxim4u.com]  [www.ic-on-line.cn] [www.ic-on-line.com] [www.ic-on-line.net] [www.alldatasheet.com.cn] [www.gdcy.com]  [www.gdcy.net]


 . . . . .
  We use cookies to deliver the best possible web experience and assist with our advertising efforts. By continuing to use this site, you consent to the use of cookies. For more information on cookies, please take a look at our Privacy Policy. X